New issue
Advanced search Search tips
Starred by 4 users
Status: Started
Area: AndroidFramework
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 Back to list
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
Project Member Comment 5 by, Mar 17 2016
Project Member Comment 6 by, Oct 6 2016
Status: Started
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



Sign in to add a comment