[Swan-dev] debian bug 853507

D. Hugh Redelmeier hugh at mimosa.com
Fri Feb 3 22:24:11 UTC 2017


Paul pointed me at 
  <https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=853507>

The warning is correct.  It doesn't really matter.  Here's a proposed fix.  
Can someone test this?
================
diff --git a/include/constants.h b/include/constants.h
index db4c991..404b788 100644
--- a/include/constants.h
+++ b/include/constants.h
@@ -216,8 +216,14 @@ extern const char *enum_short_name(enum_names *ed, unsigned long val);
 
 /* caller-allocated buffer for enum_showb */
 struct esb_buf {
-	/* enough space for any unsigned 32-bit + "??" */
-	char buf[14];
+	/* enough space for decimal rep of any unsigned long + "??"
+	 * sizeof yields log-base-256 of maximum value.
+	 * Multiplying by 241/100 converts this to the number of decimal digits
+	 * (the common log), rounded up a little (instead of 2.40654...).
+	 * The addition of 99 ensures that the division rounds up to an integer
+	 * rather than truncates.
+	 */
+	char buf[(sizeof(unsigned long) * 241 + 99) / 100 + sizeof("??")];
 };
 extern const char *enum_showb(enum_names *ed, unsigned long val, struct esb_buf *);
 extern const char *enum_show_shortb(enum_names *ed, unsigned long val, struct esb_buf *);
================


More information about the Swan-dev mailing list