]> git.draconx.ca Git - cdecl99.git/commit
libcdecl: Sidestep some possible snprintf issues.
authorNick Bowler <nbowler@draconx.ca>
Thu, 20 Jul 2023 02:12:24 +0000 (22:12 -0400)
committerNick Bowler <nbowler@draconx.ca>
Thu, 20 Jul 2023 02:12:24 +0000 (22:12 -0400)
commit779cb9b02891e3f9fc8b9620bb630cf529d76c67
treec49620287de7635cf85359c9e3bd686b40603bd1
parenta8753bb69c0455ae59fd258aad988e9613f76330
libcdecl: Sidestep some possible snprintf issues.

Adjust cdecl__emit to avoid some known problems with snprintf
implementations:

 * some implementations (e.g., newlib 1.8.2) write to the destination
   when the size is zero.
 * some implementations (e.g., HP-UX 11) return -1 when the string is
   truncated.
 * some implementations (e.g., the replacement provided by gnulib!)
   allocate memory even for trivial conversions and return -1 on malloc
   failure.

Since we currently use gnulib, only the last one is presently a concern,
but the plan is to eventually remove the library dependency on gnulib
snprintf since in reality we barely need any snprintf functionality.

Adjust the cdecl__emit implementation to simply avoid tripping over these
sorts of problems.  Other snprintf calls in the library remain as before.
src/output.c