Skip to content

Commit df57e54

Browse files
ericsalocopybara-github
authored andcommitted
upb: fix Ruby bug which allowed map.delete(key) on a frozen map
Also clean up some compiler warnings about exiting from non-void functions without returning a value. PiperOrigin-RevId: 595185251
1 parent 255f95e commit df57e54

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

ruby/ext/google/protobuf_c/map.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ static VALUE Map_delete(VALUE _self, VALUE key) {
444444
Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL);
445445
upb_MessageValue val_upb;
446446

447-
if (upb_Map_Delete(self->map, key_upb, &val_upb)) {
447+
if (upb_Map_Delete(Map_GetMutable(_self), key_upb, &val_upb)) {
448448
return Convert_UpbToRuby(val_upb, self->value_type_info, self->arena);
449449
} else {
450450
return Qnil;

ruby/ext/google/protobuf_c/shared_message.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ uint64_t shared_Message_Hash(const upb_Message* msg, const upb_MessageDef* m,
2929
uint64_t ret = _upb_Hash(data, size, seed);
3030
upb_Arena_Free(arena);
3131
return ret;
32-
} else {
33-
upb_Arena_Free(arena);
34-
upb_Status_SetErrorMessage(status, "Error calculating hash");
35-
return 0;
3632
}
33+
34+
upb_Arena_Free(arena);
35+
upb_Status_SetErrorMessage(status, "Error calculating hash");
36+
return 0;
3737
}
3838

3939
// Support function for Message_Equal
@@ -59,8 +59,9 @@ bool shared_Message_Equal(const upb_Message* m1, const upb_Message* m2,
5959
bool ret = (size1 == size2) && (memcmp(data1, data2, size1) == 0);
6060
upb_Arena_Free(arena_tmp);
6161
return ret;
62-
} else {
63-
upb_Arena_Free(arena_tmp);
64-
upb_Status_SetErrorMessage(status, "Error comparing messages");
6562
}
63+
64+
upb_Arena_Free(arena_tmp);
65+
upb_Status_SetErrorMessage(status, "Error comparing messages");
66+
return 0;
6667
}

0 commit comments

Comments
 (0)