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.
pull/230/head
Mark Landis (N6AZX) 3 years ago
parent 6752c7b254
commit 08d1ff5df0

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

Loading…
Cancel
Save

Powered by TurnKey Linux.