Add cairo_nonstring attribute

Fixes the following warnings on GCC:

../cairo/src/cairo-base64-stream.c:52:1: warning: initializer-string for array of 'char' truncates N
UL terminator but destination lacks 'nonstring' attribute (65 chars into 64 available) [-Wunterminat
ed-string-initialization]
   52 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

References:

  https://gcc.gnu.org/onlinedocs/gcc-8.1.0/gcc/Common-Variable-Attributes.html
This commit is contained in:
Luca Bacci 2026-03-27 16:14:12 +01:00
parent 21afef05af
commit ec88bcd217
5 changed files with 13 additions and 7 deletions

View file

@ -48,7 +48,7 @@ typedef struct _cairo_base64_stream {
unsigned char src[3];
} cairo_base64_stream_t;
static char const base64_table[64] =
static char const cairo_nonstring base64_table[64] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static cairo_status_t

View file

@ -148,6 +148,12 @@
#define unlikely(expr) (expr)
#endif
#if defined (__GNUC__)
#define cairo_nonstring __attribute__((nonstring))
#else
#define cairo_nonstring
#endif
#if !defined(__GNUC__) && !defined (__clang__)
#undef __attribute__
#define __attribute__(x)

View file

@ -1885,7 +1885,7 @@ typedef struct {
unsigned char src[3];
} base64_write_closure_t;
static char const base64_table[64] =
static char const cairo_nonstring base64_table[64] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static cairo_status_t

View file

@ -492,7 +492,7 @@ cairo_type1_font_write_header (cairo_type1_font_t *font,
const char *name)
{
unsigned int i;
const char spaces[50] = " ";
const char cairo_nonstring spaces[50] = " ";
_cairo_output_stream_printf (font->output,
"%%!FontType1-1.1 %s 1.0\n"
@ -555,7 +555,7 @@ cairo_type1_write_stream_encrypted (void *closure,
{
const unsigned char *in, *end;
uint16_t c, p;
static const char hex_digits[16] = "0123456789abcdef";
static const char cairo_nonstring hex_digits[16] = "0123456789abcdef";
char digits[3];
cairo_type1_font_t *font = closure;
@ -642,7 +642,7 @@ static void
cairo_type1_font_write_trailer(cairo_type1_font_t *font)
{
int i;
static const char zeros[65] =
static const char cairo_nonstring zeros[65] =
"0000000000000000000000000000000000000000000000000000000000000000\n";
for (i = 0; i < 8; i++)

View file

@ -606,7 +606,7 @@ cairo_type1_font_subset_write_encrypted (cairo_type1_font_subset_t *font,
{
const unsigned char *in, *end;
int c, p;
static const char hex_digits[16] = "0123456789abcdef";
static const char cairo_nonstring hex_digits[16] = "0123456789abcdef";
char digits[3];
in = (const unsigned char *) data;
@ -1543,7 +1543,7 @@ cairo_type1_font_subset_write_trailer(cairo_type1_font_subset_t *font)
{
const char *cleartomark_token;
int i;
static const char zeros[65] =
static const char cairo_nonstring zeros[65] =
"0000000000000000000000000000000000000000000000000000000000000000\n";