Skip to content

Commit

Permalink
upb: fix Ruby bug which allowed map.delete(key) on a frozen map
Browse files Browse the repository at this point in the history
Also clean up some compiler warnings about exiting from non-void functions without returning a value.

PiperOrigin-RevId: 595185251
  • Loading branch information
ericsalo authored and copybara-github committed Jan 2, 2024
1 parent 255f95e commit df57e54
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ruby/ext/google/protobuf_c/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ static VALUE Map_delete(VALUE _self, VALUE key) {
Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL);
upb_MessageValue val_upb;

if (upb_Map_Delete(self->map, key_upb, &val_upb)) {
if (upb_Map_Delete(Map_GetMutable(_self), key_upb, &val_upb)) {
return Convert_UpbToRuby(val_upb, self->value_type_info, self->arena);
} else {
return Qnil;
Expand Down
15 changes: 8 additions & 7 deletions ruby/ext/google/protobuf_c/shared_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ uint64_t shared_Message_Hash(const upb_Message* msg, const upb_MessageDef* m,
uint64_t ret = _upb_Hash(data, size, seed);
upb_Arena_Free(arena);
return ret;
} else {
upb_Arena_Free(arena);
upb_Status_SetErrorMessage(status, "Error calculating hash");
return 0;
}

upb_Arena_Free(arena);
upb_Status_SetErrorMessage(status, "Error calculating hash");
return 0;
}

// Support function for Message_Equal
Expand All @@ -59,8 +59,9 @@ bool shared_Message_Equal(const upb_Message* m1, const upb_Message* m2,
bool ret = (size1 == size2) && (memcmp(data1, data2, size1) == 0);
upb_Arena_Free(arena_tmp);
return ret;
} else {
upb_Arena_Free(arena_tmp);
upb_Status_SetErrorMessage(status, "Error comparing messages");
}

upb_Arena_Free(arena_tmp);
upb_Status_SetErrorMessage(status, "Error comparing messages");
return 0;
}

0 comments on commit df57e54

Please sign in to comment.