dump_log_entry: replace magic constant with a variable
Subsystems (2)
PATCH 1/1 dump_log_entry: replace magic constant with a variable
If the buffer space requirements are changed, the magic constant is hard to spot, and the failure is easily overlooked, because it may fail only under special conditions.
--- makedumpfile.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
makedumpfile.c +5 -3
@@ -3949,7 +3949,7 @@ static int dump_log_entry(char *logptr, int fp) {char *msg, *p, *bufp; -unsigned int i, text_len; +unsigned int i, text_len, buf_need;unsigned long long ts_nsec;char buf[BUFSIZE ];ulonglong nanos;
@@ -3966,9 +3966,11 @@ dump_log_entry(char *logptr, int fp) bufp = buf; bufp +=sprintf (buf,"[%5lld.%06ld] " , nanos, rem/1000 ); +/* How much buffer space is needed in the worst case */ + buf_need =sizeof ("\\xXX\n" ); +for (i =0 , p = msg; i < text_len; i++, p++) { -/* 6bytes = "\\x%02x" + '\n' + '\0' */ -if (bufp - buf >=sizeof (buf) -6 ) { +if (bufp - buf >=sizeof (buf) - buf_need) {if (write (info->fd_dumpfile, buf, bufp - buf) <0 )return FALSE; bufp = buf;
Signature · 4 lines
_______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Quoted 3 lines
If the buffer space requirements are changed, the magic constant is hard to spot, and the failure is easily overlooked, because it may fail only under special conditions.
Good change, I'll push it to devel soon.
Thanks
Atsushi Kumagai
Quoted 23 lines
Signed-off-by Petr Tesarik <[email protected]>---
makedumpfile.c| 8 +++++---1 file changed, 5 insertions(+), 3 deletions(-)makedumpfile.c +2
-1@@ -3949,7 +3949,7 @@ static int dump_log_entry(char *logptr, int fp) {char *msg, *p, *bufp; -unsigned int i, text_len; +unsigned int i, text_len, buf_need;unsigned long long ts_nsec;char buf[BUFSIZE ];ulonglong nanos;@@ -3966,9 +3966,11 @@ dump_log_entry(char *logptr, int fp) bufp = buf; bufp +=sprintf (buf,"[%5lld.%06ld] " , nanos, rem/1000 ); +/* How much buffer space is needed in the worst case */
makedumpfile.c dump_log_entry(char *logptr, int fp)
Quoted 10 lines
makedumpfile.c +3
-3+ buf_need =sizeof ("\\xXX\n" ); +for (i =0 , p = msg; i < text_len; i++, p++) { -/* 6bytes = "\\x%02x" + '\n' + '\0' */ -if (bufp - buf >=sizeof (buf) -6 ) { +if (bufp - buf >=sizeof (buf) - buf_need) {if (write (info->fd_dumpfile, buf, bufp - buf) <0 )return FALSE; bufp = buf; --
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 5 lines · On Mon, 1 Sep 2014 06:37:10 +0000 Atsushi Kumagai…
Quoted 3 lines
If the buffer space requirements are changed, the magic constant is hard to spot, and the failure is easily overlooked, because it may fail only under special conditions.
Good change, I'll push it to devel soon.
Thank you!
Petr Tesarik
Quoted 25 lines
Thanks
Atsushi KumagaiQuoted 22 lines
Signed-off-by Petr Tesarik <[email protected]>---
makedumpfile.c| 8 +++++---1 file changed, 5 insertions(+), 3 deletions(-)makedumpfile.c +1
-1@@ -3949,7 +3949,7 @@ static int dump_log_entry(char *logptr, int fp) {char *msg, *p, *bufp; -unsigned int i, text_len; +unsigned int i, text_len, buf_need;unsigned long long ts_nsec;char buf[BUFSIZE ];ulonglong nanos;@@ -3966,9 +3966,11 @@ dump_log_entry(char *logptr, int fp) bufp = buf; bufp +=sprintf (buf,"[%5lld.%06ld] " , nanos, rem/1000 );
Quoted 11 lines
makedumpfile.c dump_log_entry(char *logptr, int fp)
Quoted 11 lines
makedumpfile.c +4
-3+/* How much buffer space is needed in the worst case */ + buf_need =sizeof ("\\xXX\n" ); +for (i =0 , p = msg; i < text_len; i++, p++) { -/* 6bytes = "\\x%02x" + '\n' + '\0' */ -if (bufp - buf >=sizeof (buf) -6 ) { +if (bufp - buf >=sizeof (buf) - buf_need) {if (write (info->fd_dumpfile, buf, bufp - buf) <0 )return FALSE; bufp = buf; --
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec