New issue
Advanced search Search tips
Starred by 4 users

Issue metadata

Status: Started
Owner: ----
Cc:
Area: AndroidFramework
Priority: Medium
Type: Defect



Sign in to add a comment

Replace calls to sprintf with calls to snprintf

Project Member Reported by scro...@google.com, Jul 2 2014

Issue description

When building for Android, we get warnings like the following:

src/core/SkRegion.cpp:204:94: warning: call to 'sprintf' declared with attribute warning: sprintf is often misused; please use snprintf [enabled by default]

We actually use sprintf in a lot of places. Alternatively, we could silence the warning.
 
Project Member

Comment 1 by mtkl...@google.com, Jul 2 2014

Using snprintf where possible seems like a good idea.

If it's available (Linux), asprintf is also pretty handy: it allocates a a new char* for you that's exactly the right size.

You can do the same sort of thing manually with snprintf:
  char dummy;
  const size_t charsWeWouldHaveWritten = snprintf(&dummy, 1, "%f", number);
  SkAutoMalloc buffer(charsWeWouldHaveWritten + 1);
  SkAssertResult(charsWeWouldHaveWritten == snprintf(buffer.get(), charsWeWouldHaveWritten + 1, "%f", number);
Project Member

Comment 2 by hcm@google.com, Oct 14 2014

Labels: Area-AndroidFramework
Project Member

Comment 3 by hcm@google.com, Dec 7 2015

Labels: Hotlist-Fixit
Project Member

Comment 4 by scro...@google.com, Feb 18 2016

Labels: GoodFirstBug
Owner: ----
Status: New (was: Accepted)
Project Member

Comment 5 by caryclark@google.com, Mar 17 2016

Owner: caryclark@google.com
Project Member

Comment 6 by caryclark@google.com, Oct 6 2016

Status: Started (was: New)
Project Member

Comment 7 by bugdroid1@chromium.org, Oct 6 2016

The following revision refers to this bug:
  https://skia.googlesource.com/skia.git/+/8f1864386734cfa7650a5576ba453745a407ade2

commit 8f1864386734cfa7650a5576ba453745a407ade2
Author: caryclark <caryclark@google.com>
Date: Thu Oct 06 18:46:25 2016

remove sprintf

Most uses of sprintf are
in pathops testing.

Replace them with
SkString::appendf

and replace the remaining
with snprintf

R=scroggo@google.com
BUG=skia:2716
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2391133005

Review-Url: https://codereview.chromium.org/2391133005

[modify] https://crrev.com/8f1864386734cfa7650a5576ba453745a407ade2/src/core/SkError.cpp
[modify] https://crrev.com/8f1864386734cfa7650a5576ba453745a407ade2/src/core/SkRegion.cpp
[modify] https://crrev.com/8f1864386734cfa7650a5576ba453745a407ade2/tests/PathOpsOpCircleThreadedTest.cpp
[modify] https://crrev.com/8f1864386734cfa7650a5576ba453745a407ade2/tests/PathOpsOpCubicThreadedTest.cpp
[modify] https://crrev.com/8f1864386734cfa7650a5576ba453745a407ade2/tests/PathOpsOpLoopThreadedTest.cpp
[modify] https://crrev.com/8f1864386734cfa7650a5576ba453745a407ade2/tests/PathOpsOpRectThreadedTest.cpp
[modify] https://crrev.com/8f1864386734cfa7650a5576ba453745a407ade2/tests/PathOpsQuadLineIntersectionThreadedTest.cpp
[modify] https://crrev.com/8f1864386734cfa7650a5576ba453745a407ade2/tests/PathOpsSimplifyDegenerateThreadedTest.cpp
[modify] https://crrev.com/8f1864386734cfa7650a5576ba453745a407ade2/tests/PathOpsSimplifyQuadThreadedTest.cpp
[modify] https://crrev.com/8f1864386734cfa7650a5576ba453745a407ade2/tests/PathOpsSimplifyQuadralateralsThreadedTest.cpp
[modify] https://crrev.com/8f1864386734cfa7650a5576ba453745a407ade2/tests/PathOpsSimplifyRectThreadedTest.cpp
[modify] https://crrev.com/8f1864386734cfa7650a5576ba453745a407ade2/tests/PathOpsSimplifyTrianglesThreadedTest.cpp

Project Member

Comment 8 by carycl...@skia.org, Mar 6

Owner: ----
Remaining: 

platform_tools/android/launcher/skia_launcher.cpp:    sprintf(libraryLocation, "%s/lib%s.so", appLocation, libraryName);
tests/FontMgrAndroidParserTest.cpp:        sprintf(buffer, "%.20f", f);
tools/skdiff/skdiff_html.cpp:        sprintf(metricBuf, "%.4f%%", 100 * diff.fFractionDifference);
tools/skdiff/skdiff_html.cpp:        sprintf(metricBuf, "%.4f%%", 100 * diff.fWeightedFraction);
tools/win_dbghelp.cpp:    sprintf(szFileName, "%s%s\\%s-%04d%02d%02d-%02d%02d%02d-%ld-%ld" ext, \
tools/win_dbghelp.cpp:    sprintf( szFileName, "%s%s", szPath, szAppName );
tools/win_dbghelp.cpp:        sprintf(command, "%s -y \"%s\" -i \"%s\" -z \"%s\" -c \"%s\" -kqm >\"%s\"",
tools/win_dbghelp.cpp:    sprintf(cdbExePath, "%s\\x64\\cdb.exe", SK_CDB_PATH);
tools/win_dbghelp.cpp:    sprintf(cdbExePath, "%s\\cdb.exe", SK_CDB_PATH);

Sign in to add a comment