Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warnings in Xcode 4 #1

Open
adonoho opened this issue Jul 2, 2011 · 1 comment
Open

Warnings in Xcode 4 #1

adonoho opened this issue Jul 2, 2011 · 1 comment

Comments

@adonoho
Copy link

adonoho commented Jul 2, 2011

Gentlefolk,

Xcode 4/clang, as well as Xcode 3.*/gcc, issues 3 warnings when compiling nameprep.c, toxxx.c and util.c.

Here is one of the warnings:

/Users/awd/Projects/Chatter/ChatterX4/../../Libraries/IFUnicodeURL/IFUnicodeURL/IDNSDK/nameprep.c:76:14:{76:7-76:13}{76:16-76:17}: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare,2]
if (offset < 0 || offset > *length) {return;}
~~~~~~ ^ ~

/Users/awd/Projects/Chatter/ChatterX4/../../Libraries/IFUnicodeURL/IFUnicodeURL/IDNSDK/toxxx.c:192:31:{192:10-192:30}{192:33-192:34}: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare,2]
if ( *(dwzOutputString+i) < 0 || *(dwzOutputString+i) > 0x7F )
~~~~~~~~~~~~~~~~~~~~ ^ ~

There is, of course, a simple fix:

   if (offset > *length) {return;}

Or we could mask out the sign bit:

For nameprep.c:

#define SIZE_T_SIGN_BIT (SIZE_MAX - (SIZE_MAX / 2))

   if ((offset & SIZE_T_SIGN_BIT) || offset > *length) {return;}

For toxxx.c:

#define SIZE_SIGN_BIT (SIZE_MAX - (SIZE_MAX / 2))

    if ( (*(dwzOutputString+i) & SIZE_SIGN_BIT) || *(dwzOutputString+i) > 0x7F )

util.c is a bit harder:

Before:

    if (( c >= 0x0000 && c <= 0x002C ) ||
        (  c == 0x002E || c == 0x002F ) ||
        (  c >= 0x003A && c <= 0x0040 ) ||
        (  c >= 0x005B && c <= 0x0060 ) ||
        (  c >= 0x007B && c <= 0x007F ) )

After:

    if (((!c || c >= 0x0001) && c <= 0x002C ) ||
        (  c == 0x002E       || c == 0x002F ) ||
        (  c >= 0x003A       && c <= 0x0040 ) ||
        (  c >= 0x005B       && c <= 0x0060 ) ||
        (  c >= 0x007B       && c <= 0x007F ) )

Or, even simpler is to turn off tautological warnings ... but I would rather not.

What would be the "right" answer for this project? I've been using the simplest answers, which is to elide the checks on zero, without effect for a long while.

Andrew

@BigZaphod
Copy link
Owner

That's what I've been doing, too. I just modified my local version of the code to remove the useless conditions. Seemed easiest.

l8r
Sean

On Jul 2, 2011, at 10:42 AM, adonoho wrote:

Gentlefolk,

Xcode 4/clang, as well as Xcode 3.*/gcc, issues 3 warnings when compiling nameprep.c, toxxx.c and util.c.

Here is one of the warnings:

/Users/awd/Projects/Chatter/ChatterX4/../../Libraries/IFUnicodeURL/IFUnicodeURL/IDNSDK/nameprep.c:76:14:{76:7-76:13}{76:16-76:17}: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare,2]
if (offset < 0 || offset > *length) {return;}
~~~~~~ ^ ~

/Users/awd/Projects/Chatter/ChatterX4/../../Libraries/IFUnicodeURL/IFUnicodeURL/IDNSDK/toxxx.c:192:31:{192:10-192:30}{192:33-192:34}: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare,2]
if ( *(dwzOutputString+i) < 0 || *(dwzOutputString+i) > 0x7F )
~~~~~~~~~~~~~~~~~~~~ ^ ~

There is, of course, a simple fix:

  if (offset > *length) {return;}

Or we could mask out the sign bit:

For nameprep.c:

#define SIZE_T_SIGN_BIT (SIZE_MAX - (SIZE_MAX / 2))

  if ((offset & SIZE_T_SIGN_BIT) || offset > *length) {return;}

For toxxx.c:

#define SIZE_SIGN_BIT (SIZE_MAX - (SIZE_MAX / 2))

   if ( (*(dwzOutputString+i) & SIZE_SIGN_BIT) || *(dwzOutputString+i) > 0x7F )

util.c is a bit harder:

Before:

   if (( c >= 0x0000 && c <= 0x002C ) ||
       (  c == 0x002E || c == 0x002F ) ||
       (  c >= 0x003A && c <= 0x0040 ) ||
       (  c >= 0x005B && c <= 0x0060 ) ||
       (  c >= 0x007B && c <= 0x007F ) )

After:

   if (((!c || c >= 0x0001) && c <= 0x002C ) ||
       (  c == 0x002E       || c == 0x002F ) ||
       (  c >= 0x003A       && c <= 0x0040 ) ||
       (  c >= 0x005B       && c <= 0x0060 ) ||
       (  c >= 0x007B       && c <= 0x007F ) )

Or, even simpler is to turn off tautological warnings ... but I would rather not.

What would be the "right" answer for this project? I've been using the simplest answers, which is to elide the checks on zero, without effect for a long while.

Andrew

Reply to this email directly or view it on GitHub:
#1

mikeabdullah referenced this issue in karelia/IFUnicodeURL Nov 20, 2012
Fix static analyzer warnings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants