Skip to content

Commit e9fa83a

Browse files
author
Timothy B. Terriberry
committed
Remove realloc calls with size 0.
Apparently this is now undefined behavior in C23, so we can no no longer rely on it. Thanks to Mark Harris for the information. Fixes #2338 Thanks to Harrison Green for the report.
1 parent 8890ea3 commit e9fa83a

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/info.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,16 @@ int opus_tags_set_binary_suffix(OpusTags *_tags,
338338
ncomments=_tags->comments;
339339
ret=op_tags_ensure_capacity(_tags,ncomments);
340340
if(OP_UNLIKELY(ret<0))return ret;
341-
binary_suffix_data=
342-
(unsigned char *)_ogg_realloc(_tags->user_comments[ncomments],_len);
343-
if(OP_UNLIKELY(binary_suffix_data==NULL))return OP_EFAULT;
344-
memcpy(binary_suffix_data,_data,_len);
341+
if(_len!=0){
342+
binary_suffix_data=
343+
(unsigned char *)_ogg_realloc(_tags->user_comments[ncomments],_len);
344+
if(OP_UNLIKELY(binary_suffix_data==NULL))return OP_EFAULT;
345+
memcpy(binary_suffix_data,_data,_len);
346+
}
347+
else{
348+
_ogg_free(_tags->user_comments[ncomments]);
349+
binary_suffix_data=NULL;
350+
}
345351
_tags->user_comments[ncomments]=(char *)binary_suffix_data;
346352
_tags->comment_lengths[ncomments]=_len;
347353
return 0;
@@ -721,8 +727,14 @@ static int opus_picture_tag_parse_impl(OpusPictureTag *_pic,const char *_tag,
721727
for URLs.*/
722728
_buf_sz-=i;
723729
memmove(_buf,_buf+i,sizeof(*_buf)*_buf_sz);
724-
_buf=(unsigned char *)_ogg_realloc(_buf,_buf_sz);
725-
if(_buf_sz>0&&_buf==NULL)return OP_EFAULT;
730+
if(_buf_sz>0){
731+
_buf=(unsigned char *)_ogg_realloc(_buf,_buf_sz);
732+
if(_buf==NULL)return OP_EFAULT;
733+
}
734+
else{
735+
_ogg_free(_buf);
736+
_buf=NULL;
737+
}
726738
_pic->type=picture_type;
727739
_pic->width=width;
728740
_pic->height=height;

0 commit comments

Comments
 (0)