From 28f34e6425c63edd0db0e20effda20e1e71ba193 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Wed, 19 Jul 2023 21:15:14 -0400 Subject: [PATCH] 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. --- src/parse.y | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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; } %% -- 2.43.2