Skip to content

Commit

Permalink
Use Bytes_val to silence safe string warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Zimmermann committed May 25, 2024
1 parent 97e0e91 commit d9eb2c1
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/zlib_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
#include <caml/threads.h>
#include <caml/misc.h>

#if !defined(CAML_SAFE_STRING) && !defined(Bytes_val)
# define Bytes_val(x) String_val(x)
#endif

value zlib_adler32(value vadler, value vbuf)
{
Expand Down Expand Up @@ -397,7 +400,7 @@ CAMLprim value zlib_get_header(value vstrm)
len = header->extra_len < header->extra_max
? header->extra_len : header->extra_max;
tmp = caml_alloc_string(len);
memcpy(String_val(tmp), header->extra, len);
memcpy(Bytes_val(tmp), header->extra, len);
extra = caml_alloc_small(1, 0);
Field(extra,0) = tmp;
}
Expand All @@ -407,7 +410,7 @@ CAMLprim value zlib_get_header(value vstrm)
if (header->name != NULL) {
len = strnlen((char *)header->name, header->name_max);
tmp = caml_alloc_string(len);
memcpy(String_val(tmp), header->name, len);
memcpy(Bytes_val(tmp), header->name, len);
name = caml_alloc_small(1, 0);
Field(name,0) = tmp;
}
Expand All @@ -417,7 +420,7 @@ CAMLprim value zlib_get_header(value vstrm)
if (header->comment != NULL) {
len = strnlen((char *)header->comment, header->comm_max);
tmp = caml_alloc_string(len);
memcpy(String_val(tmp), header->comment, len);
memcpy(Bytes_val(tmp), header->comment, len);
comment = caml_alloc_small(1, 0);
Field(comment,0) = tmp;
}
Expand Down

0 comments on commit d9eb2c1

Please sign in to comment.