[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Stack module and -Wsign-compare

From: Marc Nieper-Wißkirchen
Subject: Stack module and -Wsign-compare
Date: Wed, 5 Jan 2022 11:14:51 +0100

Commit 3dc36216f168f4e752b648b19d85eab32a037827 by Paul Eggert
introduced a regression in the stack module.

If "stack.h" is included by client code that is supposed to be
compiled with "-Wsign-compare", the compiler will complain about the
comparison on line 121.

There wasn't a problem before commit
3dc36216f168f4e752b648b19d85eab32a037827 because in the previous
version both the "size" and the "allocated" field of a stack had the
same (unsigned) type.

As telling clients to compile their code without "-Wsign-compare"
isn't an option, I would like to fix it.

The simplest fix is to replace the comparison by:

stack->size == (size_t) stack->allocated

This shouldn't hide any overflows because stack->allocated is
non-negative and holds a number of allocated items and the size_t type
is by definition large enough to hold any number of allocated items.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]