]> git.draconx.ca Git - cdecl99.git/commitdiff
libcdecl: Avoid using strcpy w/ empty strings.
authorNick Bowler <nbowler@draconx.ca>
Thu, 20 Jul 2023 01:15:14 +0000 (21:15 -0400)
committerNick Bowler <nbowler@draconx.ca>
Thu, 20 Jul 2023 01:15:14 +0000 (21:15 -0400)
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.

src/parse.y

index 918cbd033a085870a70fc8f59a8058e468ebfbc5..1542c0904e5bea5320ec864646fcfd4ddb63bd64 100644 (file)
@@ -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;
 }
 
 %%