[Swan-dev] debian bug 853507
D. Hugh Redelmeier
hugh at mimosa.com
Fri Feb 3 22:47:07 UTC 2017
| From: D. Hugh Redelmeier <hugh at mimosa.com>
| The warning is correct. It doesn't really matter. Here's a proposed fix.
| Can someone test this?
There's another instance of the same problem. Here's the original fix
+ the missing bit. Still untested.
================
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 *);
diff --git a/lib/libswan/constants.c b/lib/libswan/constants.c
index 586ab90..b26425a 100644
--- a/lib/libswan/constants.c
+++ b/lib/libswan/constants.c
@@ -2395,11 +2395,10 @@ const char *sparse_val_show(sparse_names sd, unsigned long val)
const char *p = sparse_name(sd, val);
if (p == NULL) {
- /* only one! I hope that it is big enough */
- static char buf[12];
+ static struct esb_buf b; /* STATIC!! */
- snprintf(buf, sizeof(buf), "%lu??", val);
- p = buf;
+ snprintf(b.buf, sizeof(b.buf), "%lu??", val);
+ p = b.buf;
}
return p;
}
================
More information about the Swan-dev
mailing list