Closed Bug 1130244 Opened 9 years ago Closed 9 years ago

Fix clang warnings in nsprpub

Categories

(NSPR :: NSPR, defect)

4.10.9
x86
macOS
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: cpeterson, Assigned: cpeterson)

References

(Blocks 1 open bug)

Details

Attachments

(2 files, 2 obsolete files)

Attached patch nspr-clang-warnings.patch (obsolete) — Splinter Review
I see the following clang warnings when building Firefox on OS X:

> nsprpub/pr/src/io/prfdcach.c:216:18 [-Wunused-variable] unused variable 'pop'

My patch removes the unused variable `pop`.

> nsprpub/pr/src/misc/prenv.c:64:29 [-Wincompatible-pointer-types-discards-qualifiers] passing 'const char *' to parameter of type 'char *' discards qualifiers

My patch casts away the const-ness of PR_SetEnv()'s parameter because putenv() takes a non-const char* on Linux and OS X. I also cleaned up some whitespace in prenv.c.

> nsprpub/pr/src/pthreads/ptthread.c:683:12 [-Wunused-variable] unused variable 'rv'

My patch removes the initialization of `rv` (because it is redundant in the #ifdef'd code paths that use rv) and adds a (void)rv cast to suppress the -Wunused-variable warning only in the #else code path.
Attachment #8560217 - Flags: review?(wtc)
(In reply to Chris Peterson [:cpeterson] from comment #0)
> > nsprpub/pr/src/io/prfdcach.c:216:18 [-Wunused-variable] unused variable 'pop'
> 
> My patch removes the unused variable `pop`.

FWIW this was already fixed by Bug 1126408; The in tree copy of NSPR hasn't been updated to pull in the fix though.
patch v2 excludes the -Wunused-variable warning about 'pop' and just fixes these two clang warnings:

nsprpub/pr/src/misc/prenv.c:64:29 [-Wincompatible-pointer-types-discards-qualifiers] passing 'const char *' to parameter of type 'char *' discards qualifiers

nsprpub/pr/src/pthreads/ptthread.c:683:12 [-Wunused-variable] unused variable 'rv'
Assignee: wtc → cpeterson
Attachment #8560217 - Attachment is obsolete: true
Status: NEW → ASSIGNED
Attachment #8560217 - Flags: review?(wtc)
Attachment #8562574 - Flags: review?(ted)
Attached patch more-clang-warnings.patch (obsolete) — Splinter Review
Part 2: Fix more clang warnings in NSPR

nsprpub/pr/src/pthreads/ptsynch.c:325:13 [-Wunused-variable] unused variable 'rv'
nsprpub/pr/src/pthreads/ptsynch.c:340:16 [-Wunused-variable] unused variable 'rv'
nsprpub/pr/src/pthreads/ptthread.c:683:12 [-Wunused-variable] unused variable 'rv'
Attachment #8563939 - Flags: review?(ted)
patch 2 v2: oops. My patch inadvertently reversed the (0 == rv) check logic.
Attachment #8563939 - Attachment is obsolete: true
Attachment #8563939 - Flags: review?(ted)
Attachment #8564774 - Flags: review?(ted)
Comment on attachment 8562574 [details] [diff] [review]
nspr-clang-warnings-v2.patch

Review of attachment 8562574 [details] [diff] [review]:
-----------------------------------------------------------------

::: nsprpub/pr/src/misc/prenv.c
@@ +62,3 @@
>  
>      _PR_LOCK_ENV();
> +    result = _PR_MD_PUT_ENV((char*)string);

I was going to complain about this possibly being harmful, but I realize that we're already disregarding constness here, so this is just silencing the warning.
Attachment #8562574 - Flags: review?(ted) → review+
Attachment #8564774 - Flags: review?(ted) → review+
(In reply to Ted Mielczarek [:ted.mielczarek] from comment #5)
> I was going to complain about this possibly being harmful, but I realize
> that we're already disregarding constness here, so this is just silencing
> the warning.

Yes, this function is dangerous because putenv() retains the string pointer, so the caller should not modify or free it. setenv() would be safer. :(
Ted, I don't have NSPR commit privileges. Should I mark this bug checkin-needed or can you land my patches?
Flags: needinfo?(ted)
Sorry for the delay! In the future, could you attach patches against the NSPR repo and with the commit message finalized for me to commit? Takes a few steps out of the process for me. Thanks for the patches!
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Flags: needinfo?(ted)
Resolution: --- → FIXED
Version: other → 4.10.9
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: