Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

buflib: remove the 'name' member from union buflib_data

Using a length 1 char array to point to the name buffer triggers
a -Warray-bounds warning from GCC when fortified strcpy is used.

This type of construct isn't safe in general -- if the compiler
makes assumptions based on the array bound it can create subtle
bugs when accessing the array out of bounds.

Instead, add a function get_block_name() which returns a pointer
to the name field by casting. This suppresses the warning and it
should be a bit more portable.

Change-Id: I25d4f46f799022ad0ec23bef0218f7595cc741ea

+9 -5
+9 -4
firmware/buflib.c
··· 187 187 union buflib_data *block, 188 188 union buflib_data *block_end); 189 189 190 + static inline char* get_block_name(union buflib_data *block) 191 + { 192 + return (char*)&block[fidx_NAME]; 193 + } 194 + 190 195 /* Initialize buffer manager */ 191 196 void 192 197 buflib_init(struct buflib_context *ctx, void *buf, size_t size) ··· 378 383 379 384 int handle = ctx->handle_table - h_entry; 380 385 BDEBUGF("%s(): moving \"%s\"(id=%d) by %d(%d)\n", __func__, 381 - block[fidx_NAME].name, handle, shift, shift*(int)sizeof(union buflib_data)); 386 + get_block_name(block), handle, shift, shift*(int)sizeof(union buflib_data)); 382 387 new_block = block + shift; 383 388 new_start = h_entry->alloc + shift*sizeof(union buflib_data); 384 389 ··· 726 731 block[fidx_HANDLE].handle = handle; 727 732 block[fidx_OPS].ops = ops; 728 733 if (name_len > 0) 729 - strcpy(block[fidx_NAME].name, name); 734 + strcpy(get_block_name(block), name); 730 735 731 736 size_t bsize = BUFLIB_NUM_FIELDS + name_len/sizeof(union buflib_data); 732 737 union buflib_data *block_end = block + bsize; ··· 1037 1042 return NULL; 1038 1043 1039 1044 data -= len; 1040 - return data[fidx_NAME].name; 1045 + return get_block_name(data); 1041 1046 } 1042 1047 1043 1048 #ifdef DEBUG ··· 1095 1100 { 1096 1101 snprintf(buf, bufsize, "%8p: val: %4ld (%s)", 1097 1102 block, (long)block->val, 1098 - block->val > 0 ? block[fidx_NAME].name : "<unallocated>"); 1103 + block->val > 0 ? get_block_name(block) : "<unallocated>"); 1099 1104 } 1100 1105 } 1101 1106 }
-1
firmware/include/buflib.h
··· 38 38 intptr_t val; /* length of the block in n*sizeof(union buflib_data). 39 39 Includes buflib metadata overhead. A negative value 40 40 indicates block is unallocated */ 41 - char name[1]; /* name, actually a variable sized string */ 42 41 struct buflib_callbacks* ops; /* callback functions for move and shrink. Can be NULL */ 43 42 char* alloc; /* start of allocated memory area */ 44 43 union buflib_data *handle; /* pointer to entry in the handle table.