* [PATCH] dump_log_entry: replace magic constant with a variable
@ 2014-08-29 8:36 Petr Tesarik
2014-09-01 6:37 ` Atsushi Kumagai
0 siblings, 1 reply; 3+ messages in thread
From: Petr Tesarik @ 2014-08-29 8:36 UTC (permalink / raw)
To: Atsushi Kumagai; +Cc: kexec@lists.infradead.org
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.
Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
---
makedumpfile.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/makedumpfile.c b/makedumpfile.c
index b4b6eca..37dea37 100644
--- a/makedumpfile.c
+++ b/makedumpfile.c
@@ -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;
--
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply related [flat|nested] 3+ messages in thread
* RE: [PATCH] dump_log_entry: replace magic constant with a variable
2014-08-29 8:36 [PATCH] dump_log_entry: replace magic constant with a variable Petr Tesarik
@ 2014-09-01 6:37 ` Atsushi Kumagai
2014-09-01 7:17 ` Petr Tesarik
0 siblings, 1 reply; 3+ messages in thread
From: Atsushi Kumagai @ 2014-09-01 6:37 UTC (permalink / raw)
To: ptesarik@suse.cz; +Cc: kexec@lists.infradead.org
>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
>Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
>---
> makedumpfile.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
>diff --git a/makedumpfile.c b/makedumpfile.c
>index b4b6eca..37dea37 100644
>--- a/makedumpfile.c
>+++ b/makedumpfile.c
>@@ -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;
>--
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] dump_log_entry: replace magic constant with a variable
2014-09-01 6:37 ` Atsushi Kumagai
@ 2014-09-01 7:17 ` Petr Tesarik
0 siblings, 0 replies; 3+ messages in thread
From: Petr Tesarik @ 2014-09-01 7:17 UTC (permalink / raw)
To: Atsushi Kumagai; +Cc: kexec@lists.infradead.org
On Mon, 1 Sep 2014 06:37:10 +0000
Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp> wrote:
> >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
> Thanks
> Atsushi Kumagai
>
> >Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
> >---
> > makedumpfile.c | 8 +++++---
> > 1 file changed, 5 insertions(+), 3 deletions(-)
> >
> >diff --git a/makedumpfile.c b/makedumpfile.c
> >index b4b6eca..37dea37 100644
> >--- a/makedumpfile.c
> >+++ b/makedumpfile.c
> >@@ -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;
> >--
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-09-01 7:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-29 8:36 [PATCH] dump_log_entry: replace magic constant with a variable Petr Tesarik
2014-09-01 6:37 ` Atsushi Kumagai
2014-09-01 7:17 ` Petr Tesarik
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox