Skip to content

Commit

Permalink
Replace libc strdup usage with internal impl to restore musl compat. (#…
Browse files Browse the repository at this point in the history
…10811) (#10818)

Co-authored-by: Derek Perez <perezd@users.noreply.github.com>
  • Loading branch information
mkruskal-google and perezd authored Oct 25, 2022
1 parent 0d8ac76 commit 33bc6fb
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ruby/ext/google/protobuf_c/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,9 @@ VALUE build_module_from_enumdesc(VALUE _enumdesc) {
int n = upb_EnumDef_ValueCount(e);
for (int i = 0; i < n; i++) {
const upb_EnumValueDef* ev = upb_EnumDef_Value(e, i);
char* name = strdup(upb_EnumValueDef_Name(ev));
upb_Arena* arena = upb_Arena_New();
const char* src_name = upb_EnumValueDef_Name(ev);
char* name = upb_strdup2(src_name, strlen(src_name), arena);
int32_t value = upb_EnumValueDef_Number(ev);
if (name[0] < 'A' || name[0] > 'Z') {
if (name[0] >= 'a' && name[0] <= 'z') {
Expand All @@ -1303,7 +1305,7 @@ VALUE build_module_from_enumdesc(VALUE _enumdesc) {
}
}
rb_define_const(mod, name, INT2NUM(value));
free(name);
upb_Arena_Free(arena);
}

rb_define_singleton_method(mod, "lookup", enum_lookup, 1);
Expand Down

0 comments on commit 33bc6fb

Please sign in to comment.