<HTML><HEAD><TITLE>Samsung Enterprise Portal mySingle</TITLE>
<META content=IE=5 http-equiv=X-UA-Compatible>
<META content="text/html; charset=windows-1252" http-equiv=Content-Type>
<STYLE id=mysingle_style type=text/css>P {
MARGIN-BOTTOM: 5px; FONT-SIZE: 12pt; FONT-FAMILY: Arial, arial; MARGIN-TOP: 5px
}
TD {
MARGIN-BOTTOM: 5px; FONT-SIZE: 12pt; FONT-FAMILY: Arial, arial; MARGIN-TOP: 5px
}
LI {
MARGIN-BOTTOM: 5px; FONT-SIZE: 12pt; FONT-FAMILY: Arial, arial; MARGIN-TOP: 5px
}
BODY {
FONT-SIZE: 12pt; FONT-FAMILY: Arial, arial; MARGIN: 10px; LINE-HEIGHT: 1.4
}
</STYLE>
<META name=GENERATOR content=ActiveSquare></HEAD>
<BODY>
<P><SPAN style="FONT-FAMILY: Calibri">Agreed. But we need to check for other conditions like if the user is passing NULL string value or not (as it's been done in xstrdup())</SPAN></P>
<P><SPAN style="FONT-FAMILY: Calibri">In which case also, we need to exit from the execution environment.</SPAN></P>
<P> </P>
<P>Thanks and Best Regards, </P>
<P>N Ravi</P>
<P>------- <B>Original Message</B> -------</P>
<P><B>Sender</B> : Bill Spitzak<spitzak@gmail.com></P>
<P><B>Date</B> : Oct 22, 2014 01:30 (GMT+05:30)</P>
<P><B>Title</B> : Re: [cairo] [PATCH] boilerplate: Add xsprintf() and xsnprintf()</P>
<P> </P>According to the man page "If an output error is encountered, a negative <BR>value is returned." It seems very unlikely that out of memory will be <BR>the cause of the error. In fact I suspect the s*printf functions never <BR>cause memory to be allocated so this is never how they fail.<BR><BR>Also if you are going to do this, only provide the save snprintf and <BR>hide sprintf.<BR><BR>On 10/21/2014 02:06 AM, Ravi Nanjundappa wrote:<BR>> Add xsprintf() and xsnprintf() functions to boilerplate code<BR>> and replace sprintf() and snprintf() accordingly wherever applicable.<BR>><BR>> Signed-off-by: Ravi Nanjundappa <NRAVI.N@SAMSUNG.COM><BR>> ---<BR>> boilerplate/cairo-boilerplate-pdf.c | 2 +-<BR>> boilerplate/cairo-boilerplate-ps.c | 2 +-<BR>> boilerplate/cairo-boilerplate-svg.c | 2 +-<BR>> boilerplate/cairo-boilerplate-system.c | 51 ++++++++++++++++++++++++<BR>> boilerplate/cairo-boilerplate-system.h | 14 +++++++<BR>> boilerplate/cairo-boilerplate-win32-printing.c | 2 +-<BR>> boilerplate/cairo-boilerplate.c | 4 +-<BR>> perf/cairo-perf-chart.c | 14 +++----<BR>> test/cairo-test-runner.c | 2 +-<BR>> test/pdf-mime-data.c | 2 +-<BR>> util/cairo-sphinx/sphinx.c | 22 +++++-----<BR>> util/xml-to-trace.c | 2 +-<BR>> 12 files changed, 92 insertions(+), 27 deletions(-)<BR>><BR>> diff --git a/boilerplate/cairo-boilerplate-pdf.c b/boilerplate/cairo-boilerplate-pdf.c<BR>> index d76d139..a090a2a 100644<BR>> --- a/boilerplate/cairo-boilerplate-pdf.c<BR>> +++ b/boilerplate/cairo-boilerplate-pdf.c<BR>> @@ -166,7 +166,7 @@ _cairo_boilerplate_pdf_surface_write_to_png (cairo_surface_t *surface,<BR>> char command[4096];<BR>> int exitstatus;<BR>><BR>> - sprintf (command, "./pdf2png %s %s 1",<BR>> + xsprintf (command, "./pdf2png %s %s 1",<BR>> ptc->filename, filename);<BR>><BR>> exitstatus = system (command);<BR>> diff --git a/boilerplate/cairo-boilerplate-ps.c b/boilerplate/cairo-boilerplate-ps.c<BR>> index ae61239..f0c9055 100644<BR>> --- a/boilerplate/cairo-boilerplate-ps.c<BR>> +++ b/boilerplate/cairo-boilerplate-ps.c<BR>> @@ -221,7 +221,7 @@ _cairo_boilerplate_ps_surface_write_to_png (cairo_surface_t *surface,<BR>> char command[4096];<BR>> int exitstatus;<BR>><BR>> - sprintf (command, "gs -q -r72 -g%dx%d -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pngalpha -sOutputFile=%s %s %s",<BR>> + xsprintf (command, "gs -q -r72 -g%dx%d -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pngalpha -sOutputFile=%s %s %s",<BR>> ptc->width, ptc->height, filename,<BR>> ptc->level == CAIRO_PS_LEVEL_2 ? "-c 2 .setlanguagelevel -f" : "",<BR>> ptc->filename);<BR>> diff --git a/boilerplate/cairo-boilerplate-svg.c b/boilerplate/cairo-boilerplate-svg.c<BR>> index 797106e..92d856d 100644<BR>> --- a/boilerplate/cairo-boilerplate-svg.c<BR>> +++ b/boilerplate/cairo-boilerplate-svg.c<BR>> @@ -198,7 +198,7 @@ _cairo_boilerplate_svg_surface_write_to_png (cairo_surface_t *surface,<BR>> char command[4096];<BR>> int exitstatus;<BR>><BR>> - sprintf (command, "./svg2png %s %s",<BR>> + xsprintf (command, "./svg2png %s %s",<BR>> ptc->filename, filename);<BR>><BR>> exitstatus = system (command);<BR>> diff --git a/boilerplate/cairo-boilerplate-system.c b/boilerplate/cairo-boilerplate-system.c<BR>> index ec23341..36dc85f 100644<BR>> --- a/boilerplate/cairo-boilerplate-system.c<BR>> +++ b/boilerplate/cairo-boilerplate-system.c<BR>> @@ -140,6 +140,57 @@ xasprintf (char **strp,<BR>> #endif /* !HAVE_VASNPRINTF */<BR>> }<BR>><BR>> +int<BR>> +xsprintf (char *str,<BR>> + const char *fmt,<BR>> + ...)<BR>> +{<BR>> + va_list va;<BR>> + int ret;<BR>> +<BR>> + if (str == NULL) {<BR>> + fprintf (stderr, "Error: string is null\n");<BR>> + exit (1);<BR>> + }<BR>> +<BR>> + va_start (va, fmt);<BR>> + ret = vsprintf(str, fmt, va);<BR>> + va_end (va);<BR>> +<BR>> + if (ret < 0) {<BR>> + fprintf (stderr, "Error: Out of memory. Exiting.\n");<BR>> + exit (1);<BR>> + }<BR>> +<BR>> + return ret;<BR>> +}<BR>> +<BR>> +int<BR>> +xsnprintf (char *str,<BR>> + size_t size,<BR>> + const char *fmt,<BR>> + ...)<BR>> +{<BR>> + va_list va;<BR>> + int ret;<BR>> +<BR>> + if (str == NULL) {<BR>> + fprintf (stderr, "Error: string is null\n");<BR>> + exit (1);<BR>> + }<BR>> +<BR>> + va_start (va, fmt);<BR>> + ret = vsnprintf (str, size, fmt, va);<BR>> + va_end (va);<BR>> +<BR>> + if (ret < 0) {<BR>> + fprintf (stderr, "Error: Out of memory. Exiting.\n");<BR>> + exit (1);<BR>> + }<BR>> +<BR>> + return ret;<BR>> +}<BR>> +<BR>> void<BR>> xunlink (const char *pathname)<BR>> {<BR>> diff --git a/boilerplate/cairo-boilerplate-system.h b/boilerplate/cairo-boilerplate-system.h<BR>> index 2816567..7ea2a17 100644<BR>> --- a/boilerplate/cairo-boilerplate-system.h<BR>> +++ b/boilerplate/cairo-boilerplate-system.h<BR>> @@ -48,6 +48,20 @@ xasprintf (char **strp,<BR>> const char *fmt,<BR>> ...) CAIRO_BOILERPLATE_PRINTF_FORMAT(2, 3);<BR>><BR>> +#define xsprintf cairo_boilerplate_xsprintf<BR>> +int<BR>> +xsprintf (char *strp,<BR>> + const char *fmt,<BR>> + ...) CAIRO_BOILERPLATE_PRINTF_FORMAT(2, 3);<BR>> +<BR>> +#define xsnprintf cairo_boilerplate_xsnprintf<BR>> +int<BR>> +xsnprintf (char *strp,<BR>> + size_t size,<BR>> + const char *fmt,<BR>> + ...) CAIRO_BOILERPLATE_PRINTF_FORMAT(3, 4);<BR>> +<BR>> +<BR>> #define xunlink cairo_boilerplate_xunlink<BR>> void<BR>> xunlink (const char *path);<BR>> diff --git a/boilerplate/cairo-boilerplate-win32-printing.c b/boilerplate/cairo-boilerplate-win32-printing.c<BR>> index 625d52c..5cebccd 100644<BR>> --- a/boilerplate/cairo-boilerplate-win32-printing.c<BR>> +++ b/boilerplate/cairo-boilerplate-win32-printing.c<BR>> @@ -294,7 +294,7 @@ _cairo_boilerplate_win32_printing_surface_write_to_png (cairo_surface_t *surface<BR>> cairo_surface_finish (surface);<BR>> EndPage (ptc->dc);<BR>> EndDoc (ptc->dc);<BR>> - sprintf (command, "gs -q -r72 -g%dx%d -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pngalpha -sOutputFile=%s %s",<BR>> + xsprintf (command, "gs -q -r72 -g%dx%d -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pngalpha -sOutputFile=%s %s",<BR>> ptc->width + ptc->left_margin, ptc->height + ptc->bottom_margin, filename, ptc->filename);<BR>><BR>> if (system (command) != 0)<BR>> diff --git a/boilerplate/cairo-boilerplate.c b/boilerplate/cairo-boilerplate.c<BR>> index 7fdbf79..f4e07d6 100644<BR>> --- a/boilerplate/cairo-boilerplate.c<BR>> +++ b/boilerplate/cairo-boilerplate.c<BR>> @@ -935,7 +935,7 @@ cairo_boilerplate_open_any2ppm (const char *filename,<BR>> goto POPEN;<BR>> }<BR>><BR>> - len = sprintf (command, "%s %d\n", filename, page);<BR>> + len = xsprintf (command, "%s %d\n", filename, page);<BR>> if (write (sk, command, len) != len) {<BR>> close (sk);<BR>> goto POPEN;<BR>> @@ -948,7 +948,7 @@ POPEN:<BR>> #endif<BR>><BR>> *close_cb = pclose;<BR>> - sprintf (command, "%s %s %d", any2ppm, filename, page);<BR>> + xsprintf (command, "%s %s %d", any2ppm, filename, page);<BR>> return popen (command, "rb");<BR>> }<BR>><BR>> diff --git a/perf/cairo-perf-chart.c b/perf/cairo-perf-chart.c<BR>> index 738fe5c..b249d72 100644<BR>> --- a/perf/cairo-perf-chart.c<BR>> +++ b/perf/cairo-perf-chart.c<BR>> @@ -406,9 +406,9 @@ add_chart (struct chart *c,<BR>> cairo_set_font_size (c->cr, dx - 2);<BR>><BR>> if (value < 0) {<BR>> - sprintf (buf, "%.1f", -value/100 + 1);<BR>> + xsprintf (buf, "%.1f", -value/100 + 1);<BR>> } else {<BR>> - sprintf (buf, "%.1f", value/100 + 1);<BR>> + xsprintf (buf, "%.1f", value/100 + 1);<BR>> }<BR>> cairo_text_extents (c->cr, buf, &extents);<BR>><BR>> @@ -516,9 +516,9 @@ add_average (struct chart *c,<BR>> cairo_set_font_size (c->cr, dx - 2);<BR>><BR>> if (value < 0) {<BR>> - sprintf (buf, "%.1f", -value/100 + 1);<BR>> + xsprintf (buf, "%.1f", -value/100 + 1);<BR>> } else {<BR>> - sprintf (buf, "%.1f", value/100 + 1);<BR>> + xsprintf (buf, "%.1f", value/100 + 1);<BR>> }<BR>> cairo_text_extents (c->cr, buf, &extents);<BR>><BR>> @@ -643,7 +643,7 @@ done:<BR>><BR>> cairo_set_font_size (c->cr, 8);<BR>><BR>> - sprintf (buf, "%.0fs", i*v/1000);<BR>> + xsprintf (buf, "%.0fs", i*v/1000);<BR>> cairo_text_extents (c->cr, buf, &extents);<BR>><BR>> cairo_set_source_rgba (c->cr, .75, 0, 0, .95);<BR>> @@ -704,7 +704,7 @@ done:<BR>> if (y > mid)<BR>> break;<BR>><BR>> - sprintf (buf, "%.*fx", precision, i*v + 1);<BR>> + xsprintf (buf, "%.*fx", precision, i*v + 1);<BR>> cairo_text_extents (c->cr, buf, &extents);<BR>><BR>> cairo_set_source_rgba (c->cr, .75, 0, 0, .95);<BR>> @@ -986,7 +986,7 @@ add_legend (struct chart *chart)<BR>> str = chart->names[0] ?<BR>> chart->names[0] : chart->reports[0].configuration;<BR>><BR>> - sprintf (buf, "(relative to %s)", str);<BR>> + xsprintf (buf, "(relative to %s)", str);<BR>> cairo_text_extents (chart->cr, buf, &extents);<BR>><BR>> cairo_set_source_rgb (chart->cr, 1, 1, 1);<BR>> diff --git a/test/cairo-test-runner.c b/test/cairo-test-runner.c<BR>> index 3fb3ae5..221e042 100644<BR>> --- a/test/cairo-test-runner.c<BR>> +++ b/test/cairo-test-runner.c<BR>> @@ -166,7 +166,7 @@ is_running_under_debugger (void)<BR>> #if HAVE_UNISTD_H && HAVE_LIBGEN_H && __linux__<BR>> char buf[1024];<BR>><BR>> - sprintf (buf, "/proc/%d/exe", getppid ());<BR>> + xsprintf (buf, "/proc/%d/exe", getppid ());<BR>> if (readlink (buf, buf, sizeof (buf)) != -1 &&<BR>> strncmp (basename (buf), "gdb", 3) == 0)<BR>> {<BR>> diff --git a/test/pdf-mime-data.c b/test/pdf-mime-data.c<BR>> index fd5af1f..fb9f8ab 100644<BR>> --- a/test/pdf-mime-data.c<BR>> +++ b/test/pdf-mime-data.c<BR>> @@ -148,7 +148,7 @@ preamble (cairo_test_context_t *ctx)<BR>><BR>> printf ("pdf-mime-data: Please check %s to ensure it looks/prints correctly.\n", filename);<BR>><BR>> - sprintf (command, "pdfimages -j %s %s", filename, CAIRO_TEST_OUTPUT_DIR "/" BASENAME);<BR>> + xsprintf (command, "pdfimages -j %s %s", filename, CAIRO_TEST_OUTPUT_DIR "/" BASENAME);<BR>> exit_status = system (command);<BR>> free (filename);<BR>> if (exit_status) {<BR>> diff --git a/util/cairo-sphinx/sphinx.c b/util/cairo-sphinx/sphinx.c<BR>> index 3a6c04c..e181108 100644<BR>> --- a/util/cairo-sphinx/sphinx.c<BR>> +++ b/util/cairo-sphinx/sphinx.c<BR>> @@ -354,7 +354,7 @@ clients_add_command (struct clients *clients, int fd, char *info)<BR>> c->reference[len] = '\0';<BR>> }<BR>><BR>> - len = sprintf (buf, "%s\n", clients->shm_path);<BR>> + len = xsprintf (buf, "%s\n", clients->shm_path);<BR>> writen (fd, buf, len);<BR>> }<BR>><BR>> @@ -695,17 +695,17 @@ write_trace (struct clients *clients)<BR>><BR>> csum = checksum ("output/cairo-sphinx.trace");<BR>><BR>> - sprintf (buf, "output/%s.trace", csum);<BR>> + xsprintf (buf, "output/%s.trace", csum);<BR>> if (! g_file_test (buf, G_FILE_TEST_EXISTS)) {<BR>> rename ("output/cairo-sphinx.trace", buf);<BR>><BR>> - sprintf (buf, "output/%s.recording.png", csum);<BR>> + xsprintf (buf, "output/%s.recording.png", csum);<BR>> cairo_surface_write_to_png (clients->recording, buf);<BR>><BR>> for (i = 0; i < clients->count; i++) {<BR>> struct client_info *c = &clients->clients[i];<BR>> if (c->image != NULL) {<BR>> - sprintf (buf, "output/%s.%s.png", csum, c->name);<BR>> + xsprintf (buf, "output/%s.%s.png", csum, c->name);<BR>> cairo_surface_write_to_png (c->image, buf);<BR>> }<BR>> }<BR>> @@ -849,7 +849,7 @@ request_image (struct client *c,<BR>><BR>> assert (format != CAIRO_FORMAT_INVALID);<BR>><BR>> - len = sprintf (buf, ".image %lu %d %d %d %d\n",<BR>> + len = xsprintf (buf, ".image %lu %d %d %d %d\n",<BR>> closure->id, format, width, height, stride);<BR>> writen (c->sk, buf, len);<BR>><BR>> @@ -964,7 +964,7 @@ send_recording (struct client *c,<BR>> unsigned long serial;<BR>><BR>> assert (cairo_surface_get_type (source) == CAIRO_SURFACE_TYPE_RECORDING);<BR>> - len = sprintf (buf, ".recording %p %lu\n", source, closure->id);<BR>> + len = xsprintf (buf, ".recording %p %lu\n", source, closure->id);<BR>> writen (c->sk, buf, len);<BR>><BR>> /* wait for image check */<BR>> @@ -1087,7 +1087,7 @@ recorder (void *arg)<BR>> buf_size = 65536;<BR>> buf = xmalloc (buf_size);<BR>><BR>> - len = sprintf (buf, "client-command target=recording name=.recorder\n");<BR>> + len = xsprintf (buf, "client-command target=recording name=.recorder\n");<BR>> if (! writen (client.sk, buf, len))<BR>> return NULL;<BR>><BR>> @@ -1098,7 +1098,7 @@ recorder (void *arg)<BR>> if (pfd.fd < 0)<BR>> return NULL;<BR>><BR>> - len = sprintf (buf, "client-trace name=.recorder\n");<BR>> + len = xsprintf (buf, "client-trace name=.recorder\n");<BR>> if (! writen (pfd.fd, buf, len))<BR>> return NULL;<BR>><BR>> @@ -1397,11 +1397,11 @@ do_client (int fd,<BR>> buf = xmalloc (buf_size);<BR>><BR>> if (reference != NULL) {<BR>> - len = sprintf (buf,<BR>> + len = xsprintf (buf,<BR>> "client-command name=%s target=%s reference=%s\n",<BR>> name, target, reference);<BR>> } else {<BR>> - len = sprintf (buf,<BR>> + len = xsprintf (buf,<BR>> "client-command name=%s target=%s\n",<BR>> name, target);<BR>> }<BR>> @@ -1422,7 +1422,7 @@ do_client (int fd,<BR>> if (pfd.fd < 0)<BR>> return 1;<BR>><BR>> - len = sprintf (buf, "client-trace name=%s\n", name);<BR>> + len = xsprintf (buf, "client-trace name=%s\n", name);<BR>> if (! writen (pfd.fd, buf, len))<BR>> return 1;<BR>><BR>> diff --git a/util/xml-to-trace.c b/util/xml-to-trace.c<BR>> index 13b7e57..39e72a7 100644<BR>> --- a/util/xml-to-trace.c<BR>> +++ b/util/xml-to-trace.c<BR>> @@ -166,7 +166,7 @@ start_element (void *closure,<BR>> }<BR>><BR>> fprintf (trace->stream, "[");<BR>> - sprintf (trace->tail_buf, "] %s set-dash\n", offset);<BR>> + xsprintf (trace->tail_buf, "] %s set-dash\n", offset);<BR>> trace->tail = trace->tail_buf;<BR>> } else {<BR>> }<BR>><BR>-- <BR>cairo mailing list<BR>cairo@cairographics.org<BR>http://lists.cairographics.org/mailman/listinfo/cairo<BR>
<TABLE id=confidentialsignimg>
<TBODY>
<TR>
<TD NAMO_LOCK>
<P><IMG border=0 src="cid:4CBBEM6S04A2@namo.co.kr"></P></TD></TR></TBODY></TABLE></BODY></HTML><img src='http://ext.samsung.net/mailcheck/SeenTimeChecker?do=14f7afe1216e9674c99c9b2b18b9e07152c1c054c0f47df6c8b2bb558ee3c5857a7d13a75eee0fa797a3adbfcf2587a949e5ff3dfdc8681d76f80bf81d31c863cf878f9a26ce15a0' border=0 width=0 height=0 style='display:none'>