Fix ckpt_write_err() check for empty string
PATCH 1/1 Fix ckpt_write_err() check for empty string
The test for empty error strings does not work because we always add 2 to len before testing if it's 0. Fix by checking before adding 2.
--- checkpoint/checkpoint.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
checkpoint/checkpoint.c +2 -2
@@ -258,11 +258,11 @@ int ckpt_write_err(struct ckpt_ctx *ctx, char *pre, char *fmt, ...) } str = ctx->err_string; - len =strlen (str +1 ) +2 ;/* leading and trailing '\0' */ - + len =strlen (str +1 );if (len ==0 )/* empty error string */ return 0 ; + len +=2 ;/* leading and trailing '\0' */ ret =ckpt_write_obj_type (ctx,NULL ,0 ,CKPT_HDR_ERROR );if (!ret) ret =ckpt_write_string (ctx, str, len);
Signature · 1 line
1.5.6.3
A message that is not in the archive (sent off-list or not yet received): 1254531987-13008-1-git-send-email-matthltc-r/[email protected]
Quoted 2 lines · Matt Helsley
The test for empty error strings does not work because we always add 2 to len before testing if it's 0. Fix by checking before adding 2.
It occurs to me that this should be an [RFC] patch because there are two alternative solutions:
1. Compare to 2 after addition
2. Drop the check altogether -- the result will be an empty string in the checkpoint image. This means that ckpt_write_err() would always output a CKPT_HDR_ERROR with at least an empty string. I wonder if this wouldn't be preferrable to no CKPT_HDR_ERROR at all.
Cheers,
-Matt Helsley
Quoted 27 lines
Signed-off-by Matt Helsley <matthltc-r/[email protected]>--- checkpoint/checkpoint.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)checkpoint/checkpoint.c +2
-2@@ -258,11 +258,11 @@ int ckpt_write_err(struct ckpt_ctx *ctx, char *pre, char *fmt, ...) } str = ctx->err_string; - len =strlen (str +1 ) +2 ;/* leading and trailing '\0' */ - + len =strlen (str +1 );if (len ==0 )/* empty error string */ return 0 ; + len +=2 ;/* leading and trailing '\0' */ ret =ckpt_write_obj_type (ctx,NULL ,0 ,CKPT_HDR_ERROR );if (!ret) ret =ckpt_write_string (ctx, str, len);Signature · 1 line
1.5.6.3