nsSmartCardMonitor.cpp:90:25: warning: unused variable ‘current’ [-Wunused-variable]

RESOLVED FIXED in mozilla20

Status

()

defect
RESOLVED FIXED
7 years ago
7 years ago

People

(Reporter: dholbert, Assigned: dholbert)

Tracking

(Blocks 1 bug)

Trunk
mozilla20
x86_64
Linux
Points:
---
Dependency tree / graph
Bug Flags:
in-testsuite -

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

Build warning:
{
security/manager/ssl/src/nsSmartCardMonitor.cpp:90:25: warning: unused variable ‘current’ [-Wunused-variable]
}

from the top change in this cset:
https://hg.mozilla.org/mozilla-central/diff/9a4531d2d243/security/manager/ssl/src/nsSmartCardMonitor.cpp

The code in question is:

> 87 nsresult
> 88 SmartCardThreadList::Add(SmartCardMonitoringThread *thread)
> 89 {
> 90   SmartCardThreadEntry *current = new SmartCardThreadEntry(thread, head, nullptr,
> 91                                                            &head);
> 92   // OK to forget current here, it's on the list
> 93   return thread->Start();
> 94 }
https://mxr.mozilla.org/mozilla-central/source/security/manager/ssl/src/nsSmartCardMonitor.cpp#87

Given the code-comment there, it looks like we're *intentionally* not using "current", and it's not a problem.

We can tell the compiler this is OK by adding
 (void)current;
Posted patch fixSplinter Review
This patch also fixes a whitespace style issue (add spaces around "=") and a typo (s/passwd/passed/) in contextual code.
Assignee: nobody → dholbert
Attachment #687310 - Flags: review?(bsmith)
Comment on attachment 687310 [details] [diff] [review]
fix

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

::: security/manager/ssl/src/nsSmartCardMonitor.cpp
@@ +73,5 @@
>  void
>  SmartCardThreadList::Remove(SECMODModule *aModule)
>  {
>    SmartCardThreadEntry *current;
> +  for (current = head; current; current = current->next) {

Nit: could fold the declaration into the for loop head too.

@@ +90,5 @@
>    SmartCardThreadEntry *current = new SmartCardThreadEntry(thread, head, nullptr,
>                                                             &head);
> +  // OK to forget current here, it's on the list.
> +  // (Use (void) to silence GCC "unused variable" warning.)
> +  (void)current;

How about mozilla::unused <<current?
Attachment #687310 - Flags: review?(bsmith) → review+
nice, I forgot about the mozilla::unused construct.  Thanks for reminding me -- I'll use that. (and tweak the "for" loop as you suggest, too)
Landed: https://hg.mozilla.org/integration/mozilla-inbound/rev/e0f8cc72dd06

Also: while adding the #include for unused.h at the top of the file, I noticed that we had an unnecessary "#include <assert.h>" a little lower, separated from all the other #includes. I removed it, because it's not needed or used.  (It actually was unused even back when it was added, in this CVS commit: http://bonsai.mozilla.org/cvsview2.cgi?diff_mode=context&whitespace_mode=show&root=/cvsroot&subdir=mozilla/security/manager/ssl/src&command=DIFF_FRAMESET&file=nsSmartCardMonitor.cpp&rev2=1.2&rev1=1.1 )
Status: NEW → ASSIGNED
Flags: in-testsuite-
oops, my commit message ended up being slightly incorrect:
>  Bug 817176: Add "(void)" cast to silence GCC unused-var warning for an intentionally-unused variable. r=bsmith
... since I ended up using "unused <<" instead of (void).

It gets the point across, though, and I don't think it's worth a backout & re-landing, so I'll just leave it.
https://hg.mozilla.org/mozilla-central/rev/e0f8cc72dd06
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla20
You need to log in before you can comment on or make changes to this bug.