[PATCH 2/2] Avoid signed/unsigned comparsions
Eric W. Biederman
ebiederm at xmission.com
Thu Mar 3 16:53:33 EST 2011
Simon Horman <horms at verge.net.au> writes:
At least the change of ret from ssize_t to size_t is bogus.
pread returns a ssize_t and I am comparing it against sizeof(X). We
might as we type convert in the comparison. That test is a necessary
and real comparison and I don't think hiding that fact with an implicit
conversion does anything but obfuscate things.
> Cc: Eric W. Biederman <ebiederm at xmission.com>
> Signed-off-by: Simon Horman <horms at verge.net.au>
> ---
> vmcore-dmesg/vmcore-dmesg.c | 12 ++++--------
> 1 files changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/vmcore-dmesg/vmcore-dmesg.c b/vmcore-dmesg/vmcore-dmesg.c
> index 365e293..f7eef16 100644
> --- a/vmcore-dmesg/vmcore-dmesg.c
> +++ b/vmcore-dmesg/vmcore-dmesg.c
> @@ -79,8 +79,7 @@ static void read_elf32(int fd)
> {
> Elf32_Ehdr ehdr32;
> Elf32_Phdr *phdr32;
> - size_t phdrs32_size, phdrs_size;
> - ssize_t ret, i;
> + ssize_t phdrs32_size, phdrs_size, ret, i;
>
> ret = pread(fd, &ehdr32, sizeof(ehdr32), 0);
> if (ret != sizeof(ehdr32)) {
> @@ -151,8 +150,7 @@ static void read_elf64(int fd)
> {
> Elf64_Ehdr ehdr64;
> Elf64_Phdr *phdr64;
> - size_t phdrs_size;
> - ssize_t ret, i;
> + size_t phdrs_size, ret, i;
>
> ret = pread(fd, &ehdr64, sizeof(ehdr64), 0);
> if (ret != sizeof(ehdr)) {
> @@ -240,8 +238,7 @@ static void scan_vmcoreinfo(char *start, size_t size)
> };
>
> for (pos = start; pos <= last; pos = eol + 1) {
> - size_t len;
> - int i;
> + size_t len, i;
> /* Find the end of the current line */
> for (eol = pos; (eol <= last) && (*eol != '\n') ; eol++)
> ;
> @@ -274,8 +271,7 @@ static void scan_vmcoreinfo(char *start, size_t size)
> static void scan_notes(int fd, loff_t start, loff_t lsize)
> {
> char *buf, *last, *note, *next;
> - size_t size;
> - ssize_t ret;
> + ssize_t size, ret;
>
> if (lsize > LONG_MAX) {
> fprintf(stderr, "Unable to handle note section of %llu bytes\n",
More information about the kexec
mailing list