Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
safe-printf.h
Go to the documentation of this file.
1
// SPDX-License-Identifier: GPL-2.0-or-later
2
//
3
// Safer replacement for sprintf()
4
//
5
// When invoked with a char buffer of size known to compiler, it will call
6
// snprintf passing correct buffer size without programmer specifying one explicitly.
7
//
8
// When buffer size is only known at runtime, one should use snprintf instead.
9
10
#ifndef INKSCAPE_SAFE_PRINTF_H
11
#define INKSCAPE_SAFE_PRINTF_H
12
13
#include <cstdarg>
14
#include <cstddef>
15
#include <glib/gmacros.h>
16
17
template
<
size_t
N>
18
int
G_GNUC_PRINTF
(2, 3) safeprintf(
char
(&
buf
)[
N
], const
char
*
fmt
, ...) {
19
va_list args;
20
va_start
(args,
fmt
);
21
auto
len
= vsnprintf(
buf
,
N
,
fmt
, args);
22
va_end
(args);
23
return
len
;
24
}
25
26
#endif
buf
int buf
Definition
pixelstreamer.cpp:67
va_end
va_end(args)
G_GNUC_PRINTF
int G_GNUC_PRINTF(2, 3) safeprintf(char(&buf)[N]
len
auto len
Definition
safe-printf.h:21
fmt
int const char * fmt
Definition
safe-printf.h:18
va_start
int const char va_start(args, fmt)
N
size_t N
Definition
solve-bezier-one-d.cpp:23
src
util
safe-printf.h
Generated on Sun Jun 22 2025 04:02:08 for Inkscape by
1.9.8