Skip to content

Commit

Permalink
COMP: Suppress -Wformat-nonliteral warning in diff tensor example
Browse files Browse the repository at this point in the history
Suppress `-Wformat-nonliteral` warning in diffusion tensor
reconstruction image filter example: pass the string literals directly
to `snprintf` without using an intermediate variable.

Fixes:
```
[CTest: warning matched]
 /Users/builder/externalExamples/Filtering/DiffusionTensor3DReconstructionImageFilter.cxx:254:46:
 warning: format string is not a string literal [-Wformat-nonliteral]
        snprintf(filename, sizeof(filename), fn.c_str(), referenceImageIndex);
                                             ^~~~~~~~~~
[CTest: warning matched]
 /Users/builder/externalExamples/Filtering/DiffusionTensor3DReconstructionImageFilter.cxx:260:46:
 warning: format string is not a string literal [-Wformat-nonliteral]
        snprintf(filename, sizeof(filename), fn.c_str(), i);
                                             ^~~~~~~~~~
[CTest: warning suppressed] 2 warnings generated.
```

raised for example in:
https://open.cdash.org/viewBuildError.php?type=1&onlydeltap&buildid=9582771

Left behind in commit 001a1a7.
  • Loading branch information
jhlegarreta committed May 1, 2024
1 parent a895d7f commit abc789e
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,15 @@ main(int argc, char * argv[])
if (DiffusionVectors->ElementAt(i).two_norm() <=
0.0) // this is a reference image
{
std::string fn("ReferenceImage%d.mhd");
snprintf(filename, sizeof(filename), fn.c_str(), referenceImageIndex);
snprintf(filename,
sizeof(filename),
"ReferenceImage%d.mhd",
referenceImageIndex);
++referenceImageIndex;
}
else
{
std::string fn("Gradient%d.mhd");
snprintf(filename, sizeof(filename), fn.c_str(), i);
snprintf(filename, sizeof(filename), "Gradient%d.mhd", i);
}
gradientWriter->SetFileName(filename);
gradientWriter->Update();
Expand Down

0 comments on commit abc789e

Please sign in to comment.