isdigit() may return any non-zero result for success

POSIX states that the return value of isdigit(): "shall return non-zero
if c is a decimal digit; otherwise, they shall return 0."

Thus the form:

  ok &= isdigit(x)

is invalid since the runtime is not required to return 1.

This bug was observed on Debian 11 while using the clang toolchain.
In that environment, isdigit() returns 2048 for a positive match.
This commit is contained in:
Mark Landis (N6AZX) 2022-12-27 15:04:09 -08:00
parent 6752c7b254
commit 08d1ff5df0

View file

@ -152,7 +152,7 @@ bool CDmridDir::IsValidDmrid(const char *sz)
ok = true;
for ( size_t i = 0; (i < n) && ok; i++ )
{
ok &= ::isdigit(sz[i]);
ok = ::isdigit(sz[i]);
}
}
return ok;