[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 08/11] Fix __argp_fmtstream_point()'s return type and comparisons
From: |
Robbie Harwood |
Subject: |
[PATCH 08/11] Fix __argp_fmtstream_point()'s return type and comparisons with it |
Date: |
Mon, 25 Oct 2021 17:55:41 -0400 |
From: Peter Jones <pjones@redhat.com>
gcc -Werror=sign-compare produces:
argp-help.c:1545:15: error: comparison of integer expressions of different
signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Werror=sign-compare]
1545 | > __argp_fmtstream_lmargin (stream))
| ^
Some code seems to assume the point_col field (which
__argp_fmtstream_point() returns) can be -1, and it's an ssize_t, so
this makes the function correctly return ssize_t in all cases, and also
fixes the comparison to check for the -1 case.
Signed-off-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
---
lib/argp-fmtstream.h | 6 +++---
lib/argp-help.c | 7 +++++--
2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/lib/argp-fmtstream.h b/lib/argp-fmtstream.h
index 3384a0012..f47e24c5c 100644
--- a/lib/argp-fmtstream.h
+++ b/lib/argp-fmtstream.h
@@ -164,8 +164,8 @@ extern size_t __argp_fmtstream_set_wmargin
(argp_fmtstream_t __fs,
size_t __wmargin);
/* Return the column number of the current output point in __FS. */
-extern size_t argp_fmtstream_point (argp_fmtstream_t __fs);
-extern size_t __argp_fmtstream_point (argp_fmtstream_t __fs);
+extern ssize_t argp_fmtstream_point (argp_fmtstream_t __fs);
+extern ssize_t __argp_fmtstream_point (argp_fmtstream_t __fs);
#endif
/* Internal routines. */
@@ -272,7 +272,7 @@ __argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, size_t
__wmargin)
}
/* Return the column number of the current output point in __FS. */
-ARGP_FS_EI size_t
+ARGP_FS_EI ssize_t
__argp_fmtstream_point (argp_fmtstream_t __fs)
{
if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
diff --git a/lib/argp-help.c b/lib/argp-help.c
index 84013b002..93e40cad7 100644
--- a/lib/argp-help.c
+++ b/lib/argp-help.c
@@ -1631,7 +1631,9 @@ argp_doc (const struct argp *argp, const struct
argp_state *state,
else
__argp_fmtstream_puts (stream, text);
- if (__argp_fmtstream_point (stream) > __argp_fmtstream_lmargin (stream))
+ if (__argp_fmtstream_point (stream) < 0 ||
+ (size_t)__argp_fmtstream_point (stream)
+ > __argp_fmtstream_lmargin (stream))
__argp_fmtstream_putc (stream, '\n');
anything = 1;
@@ -1652,7 +1654,8 @@ argp_doc (const struct argp *argp, const struct
argp_state *state,
__argp_fmtstream_putc (stream, '\n');
__argp_fmtstream_puts (stream, text);
free ((char *) text);
- if (__argp_fmtstream_point (stream)
+ if (__argp_fmtstream_point (stream) < 0 ||
+ (size_t)__argp_fmtstream_point (stream)
> __argp_fmtstream_lmargin (stream))
__argp_fmtstream_putc (stream, '\n');
anything = 1;
--
2.33.0
- [PATCH 00/11] Code hygiene fixes from grub, Robbie Harwood, 2021/10/25
- [PATCH 08/11] Fix __argp_fmtstream_point()'s return type and comparisons with it,
Robbie Harwood <=
- [PATCH 07/11] Make CFLAGS less painful, Robbie Harwood, 2021/10/25
- [PATCH 02/11] argp-parse.c (__argp_input): Don't crash if pstate is NULL, Robbie Harwood, 2021/10/25
- [PATCH 05/11] Fix width computation, Robbie Harwood, 2021/10/25
- [PATCH 01/11] Fix base64 module to work with grub codebase, Robbie Harwood, 2021/10/25
- [PATCH 06/11] Make gnulib's regcomp not abort(), Robbie Harwood, 2021/10/25
- [PATCH 03/11] gnulib/regexec: Fix possible null-dereference, Robbie Harwood, 2021/10/25
- [PATCH 11/11] Fixup for -Werror=ignored-qualifiers issues, Robbie Harwood, 2021/10/25
- [PATCH 04/11] gnulib/regexec: Resolve unused variable, Robbie Harwood, 2021/10/25