]> granicus.if.org Git - graphviz/commitdiff
expose itos buffer size as a constant
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 11 Sep 2021 18:40:05 +0000 (11:40 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 18 Sep 2021 22:14:15 +0000 (15:14 -0700)
Elsewhere in Graphviz we sometimes need to print ints into fixed sized buffers,
but not using itos. So it is useful to have a value for the number of bytes this
requires that is also regularly validated by the Graphviz test suite. That is,
uses of this constant should be robust to future environment/platform changes,
because the itos tests will fail, prompting an update of this constant, that
will then correctly affect all usages of this.

lib/cgraph/itos.h

index 6f3cefd5b1bef189c9b46b7a44dc48a0ee912e74..5d0d24d6c4a7488d4e0fb9fdeef2fc6ed01ee4d1 100644 (file)
@@ -2,9 +2,12 @@
 
 #include <stdio.h>
 
+// maximum number of bytes needed to print a NUL-terminated int
+enum { CHARS_FOR_NUL_TERM_INT = 12 };
+
 // return type of itos below
 struct itos_ {
-  char str[12];
+  char str[CHARS_FOR_NUL_TERM_INT];
 };
 
 /** convert an integer to a string