git://git.onelab.eu
/
sliver-openvswitch.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
ofp-util: Don't return static data in ofputil_packet_in_reason_to_string().
[sliver-openvswitch.git]
/
lib
/
ofp-util.c
diff --git
a/lib/ofp-util.c
b/lib/ofp-util.c
index
cc2dc36
..
26da477
100644
(file)
--- a/
lib/ofp-util.c
+++ b/
lib/ofp-util.c
@@
-2656,11
+2656,13
@@
ofputil_encode_packet_in(const struct ofputil_packet_in *pin,
return packet;
}
return packet;
}
+/* Returns a string form of 'reason'. The return value is either a statically
+ * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
+ * 'bufsize' should be at least OFPUTIL_PACKET_IN_REASON_BUFSIZE. */
const char *
const char *
-ofputil_packet_in_reason_to_string(enum ofp_packet_in_reason reason)
+ofputil_packet_in_reason_to_string(enum ofp_packet_in_reason reason,
+ char *reasonbuf, size_t bufsize)
{
{
- static char s[INT_STRLEN(int) + 1];
-
switch (reason) {
case OFPR_NO_MATCH:
return "no_match";
switch (reason) {
case OFPR_NO_MATCH:
return "no_match";
@@
-2671,8
+2673,8
@@
ofputil_packet_in_reason_to_string(enum ofp_packet_in_reason reason)
case OFPR_N_REASONS:
default:
case OFPR_N_REASONS:
default:
- s
printf(s
, "%d", (int) reason);
- return
s
;
+ s
nprintf(reasonbuf, bufsize
, "%d", (int) reason);
+ return
reasonbuf
;
}
}
}
}
@@
-2683,7
+2685,12
@@
ofputil_packet_in_reason_from_string(const char *s,
int i;
for (i = 0; i < OFPR_N_REASONS; i++) {
int i;
for (i = 0; i < OFPR_N_REASONS; i++) {
- if (!strcasecmp(s, ofputil_packet_in_reason_to_string(i))) {
+ char reasonbuf[OFPUTIL_PACKET_IN_REASON_BUFSIZE];
+ const char *reason_s;
+
+ reason_s = ofputil_packet_in_reason_to_string(i, reasonbuf,
+ sizeof reasonbuf);
+ if (!strcasecmp(s, reason_s)) {
*reason = i;
return true;
}
*reason = i;
return true;
}