New issue
Advanced search Search tips

Issue 2716 link

Starred by 4 users

Issue metadata

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

Sign in to add a comment

Replace calls to sprintf with calls to snprintf

Project Member Reported by, 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, 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, Oct 14 2014

Labels: Area-AndroidFramework
Project Member

Comment 3 by, Dec 7 2015

Labels: Hotlist-Fixit
Project Member

Comment 4 by, Feb 18 2016

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

Comment 5 by, Mar 17 2016

Project Member

Comment 6 by, Oct 6 2016

Status: Started (was: New)
Project Member

Comment 7 by, Oct 6 2016

The following revision refers to this bug:

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

remove sprintf

Most uses of sprintf are
in pathops testing.

Replace them with

and replace the remaining
with snprintf



Project Member

Comment 8 by, Mar 6 2018

Owner: ----

platform_tools/android/launcher/skia_launcher.cpp:    sprintf(libraryLocation, "%s/", 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