From: Nick Bowler Date: Thu, 20 Jul 2023 01:15:14 +0000 (-0400) Subject: libcdecl: Avoid using strcpy w/ empty strings. X-Git-Tag: v1.3~107 X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/commitdiff_plain/28f34e6425c63edd0db0e20effda20e1e71ba193?hp=b126a7b2d76bffbe16dd439b8049898442191536 libcdecl: Avoid using strcpy w/ empty strings. The parser is currently using strcpy to copy constant empty strings; it is just as easy to explicitly assign the single zero byte instead. Since these are the only use of strcpy in the library, and for whatever reason GCC is not optimizing out these strcpy calls, on ELF hosts this saves a PLT entry in the shared library and everything associated with that too. --- diff --git a/src/parse.y b/src/parse.y index 918cbd0..1542c09 100644 --- a/src/parse.y +++ b/src/parse.y @@ -375,7 +375,7 @@ declspec_noid: declspec_notype | typespec_noid vla_ident: T_IDENT | T_ASTERISK { ALLOC($$, sizeof ""); - strcpy($$, ""); + *$$ = 0; } array: T_LBRACKET array_length T_RBRACKET { @@ -572,7 +572,7 @@ array_length: T_UINT { english_vla: T_IDENT | { ALLOC($$, sizeof ""); - strcpy($$, ""); + *$$ = 0; } %%