2 * This file is part of cparser.
3 * Copyright (C) 2007-2009 Matthias Braun <matze@braunis.de>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 #include "format_check.h"
29 #include "diagnostic.h"
33 #include "lang_features.h"
35 typedef enum format_flag_t {
37 FMT_FLAG_HASH = 1U << 0,
38 FMT_FLAG_ZERO = 1U << 1,
39 FMT_FLAG_MINUS = 1U << 2,
40 FMT_FLAG_SPACE = 1U << 3,
41 FMT_FLAG_PLUS = 1U << 4,
42 FMT_FLAG_TICK = 1U << 5
45 typedef unsigned format_flags_t;
47 typedef enum format_length_modifier_t {
58 /* only in microsoft mode */
63 } format_length_modifier_t;
65 typedef struct format_spec_t {
66 const char *name; /**< name of the function */
67 format_kind_t fmt_kind; /**< kind */
68 unsigned fmt_idx; /**< index of the format string */
69 unsigned arg_idx; /**< index of the first argument */
72 static const char* get_length_modifier_name(const format_length_modifier_t mod)
74 static const char* const names[] = {
85 /* only in microsoft mode */
88 [FMT_MOD_I32] = "I32",
91 assert(mod < lengthof(names));
95 static void warn_invalid_length_modifier(const source_position_t *pos,
96 const format_length_modifier_t mod,
97 const utf32 conversion)
100 "invalid length modifier '%s' for conversion specifier '%%%c'",
101 get_length_modifier_name(mod), conversion
106 * Check printf-style format. Returns number of expected arguments.
108 static int internal_check_printf_format(const expression_t *fmt_expr,
109 const call_argument_t *arg,
110 const format_spec_t *spec)
112 while (fmt_expr->kind == EXPR_UNARY_CAST_IMPLICIT) {
113 fmt_expr = fmt_expr->unary.value;
117 * gettext results in expressions like (X ? "format_string" : Y)
118 * we assume the left part is the format string
120 if (fmt_expr->kind == EXPR_CONDITIONAL) {
121 conditional_expression_t const *const c = &fmt_expr->conditional;
122 expression_t const * t = c->true_expression;
125 int const nt = internal_check_printf_format(t, arg, spec);
126 int const nf = internal_check_printf_format(c->false_expression, arg, spec);
127 return nt > nf ? nt : nf;
130 if (fmt_expr->kind != EXPR_STRING_LITERAL
131 && fmt_expr->kind != EXPR_WIDE_STRING_LITERAL)
134 const char *string = fmt_expr->literal.value.begin;
135 size_t size = fmt_expr->literal.value.size;
136 const char *c = string;
138 const source_position_t *pos = &fmt_expr->base.source_position;
139 unsigned num_fmt = 0;
140 unsigned num_args = 0;
142 for (fmt = *c; fmt != '\0'; fmt = *(++c)) {
148 warningf(pos, "dangling %% in format string");
157 format_flags_t fmt_flags = FMT_FLAG_NONE;
160 fmt_flags |= FMT_FLAG_ZERO;
163 /* argument selector or minimum field width */
167 } while (isdigit(fmt));
169 /* digit string was ... */
171 /* ... argument selector */
172 fmt_flags = FMT_FLAG_NONE; /* reset possibly set 0-flag */
176 /* ... minimum field width */
182 case '#': flag = FMT_FLAG_HASH; break;
183 case '0': flag = FMT_FLAG_ZERO; break;
184 case '-': flag = FMT_FLAG_MINUS; break;
185 case '\'': flag = FMT_FLAG_TICK; break;
188 if (fmt_flags & FMT_FLAG_PLUS) {
189 warningf(pos, "' ' is overridden by prior '+' in conversion specification %u", num_fmt);
191 flag = FMT_FLAG_SPACE;
195 if (fmt_flags & FMT_FLAG_SPACE) {
196 warningf(pos, "'+' overrides prior ' ' in conversion specification %u", num_fmt);
198 flag = FMT_FLAG_PLUS;
201 default: goto break_fmt_flags;
203 if (fmt_flags & flag) {
204 warningf(pos, "repeated flag '%c' in conversion specification %u", (char)fmt, num_fmt);
211 /* minimum field width */
216 warningf(pos, "missing argument for '*' field width in conversion specification %u", num_fmt);
219 const type_t *const arg_type = arg->expression->base.type;
220 if (arg_type != type_int) {
221 warningf(pos, "argument for '*' field width in conversion specification %u is not an 'int', but an '%T'", num_fmt, arg_type);
225 while (isdigit(fmt)) {
238 warningf(pos, "missing argument for '*' precision in conversion specification %u", num_fmt);
241 const type_t *const arg_type = arg->expression->base.type;
242 if (arg_type != type_int) {
243 warningf(pos, "argument for '*' precision in conversion specification %u is not an 'int', but an '%T'", num_fmt, arg_type);
247 /* digit string may be omitted */
248 while (isdigit(fmt)) {
254 /* length modifier */
255 format_length_modifier_t fmt_mod;
261 fmt_mod = FMT_MOD_hh;
271 fmt_mod = FMT_MOD_ll;
277 case 'L': fmt = *(++c); fmt_mod = FMT_MOD_L; break;
278 case 'j': fmt = *(++c); fmt_mod = FMT_MOD_j; break;
279 case 't': fmt = *(++c); fmt_mod = FMT_MOD_t; break;
280 case 'z': fmt = *(++c); fmt_mod = FMT_MOD_z; break;
281 case 'q': fmt = *(++c); fmt_mod = FMT_MOD_q; break;
285 fmt = *(++c); fmt_mod = FMT_MOD_w;
287 fmt_mod = FMT_MOD_NONE;
292 fmt = *(++c); fmt_mod = FMT_MOD_I;
297 fmt_mod = FMT_MOD_I32;
302 } else if (fmt == '6') {
306 fmt_mod = FMT_MOD_I64;
313 fmt_mod = FMT_MOD_NONE;
317 fmt_mod = FMT_MOD_NONE;
322 type_t *expected_type;
323 type_qualifiers_t expected_qual = TYPE_QUALIFIER_NONE;
324 format_flags_t allowed_flags;
329 case FMT_MOD_NONE: expected_type = type_int; break;
330 case FMT_MOD_hh: expected_type = type_int; break; /* TODO promoted signed char */
331 case FMT_MOD_h: expected_type = type_int; break; /* TODO promoted short */
332 case FMT_MOD_l: expected_type = type_long; break;
333 case FMT_MOD_ll: expected_type = type_long_long; break;
334 case FMT_MOD_j: expected_type = type_intmax_t; break;
335 case FMT_MOD_z: expected_type = type_ssize_t; break;
336 case FMT_MOD_t: expected_type = type_ptrdiff_t; break;
337 case FMT_MOD_I: expected_type = type_ptrdiff_t; break;
338 case FMT_MOD_I32: expected_type = type_int32; break;
339 case FMT_MOD_I64: expected_type = type_int64; break;
342 warn_invalid_length_modifier(pos, fmt_mod, fmt);
345 allowed_flags = FMT_FLAG_MINUS | FMT_FLAG_SPACE | FMT_FLAG_PLUS | FMT_FLAG_ZERO;
351 allowed_flags = FMT_FLAG_MINUS | FMT_FLAG_HASH | FMT_FLAG_ZERO;
352 goto eval_fmt_mod_unsigned;
355 allowed_flags = FMT_FLAG_MINUS | FMT_FLAG_ZERO;
356 eval_fmt_mod_unsigned:
358 case FMT_MOD_NONE: expected_type = type_unsigned_int; break;
359 case FMT_MOD_hh: expected_type = type_int; break; /* TODO promoted unsigned char */
360 case FMT_MOD_h: expected_type = type_int; break; /* TODO promoted unsigned short */
361 case FMT_MOD_l: expected_type = type_unsigned_long; break;
362 case FMT_MOD_ll: expected_type = type_unsigned_long_long; break;
363 case FMT_MOD_j: expected_type = type_uintmax_t; break;
364 case FMT_MOD_z: expected_type = type_size_t; break;
365 case FMT_MOD_t: expected_type = type_uptrdiff_t; break;
366 case FMT_MOD_I: expected_type = type_size_t; break;
367 case FMT_MOD_I32: expected_type = type_unsigned_int32; break;
368 case FMT_MOD_I64: expected_type = type_unsigned_int64; break;
371 warn_invalid_length_modifier(pos, fmt_mod, fmt);
385 case FMT_MOD_l: /* l modifier is ignored */
386 case FMT_MOD_NONE: expected_type = type_double; break;
387 case FMT_MOD_L: expected_type = type_long_double; break;
390 warn_invalid_length_modifier(pos, fmt_mod, fmt);
393 allowed_flags = FMT_FLAG_MINUS | FMT_FLAG_SPACE | FMT_FLAG_PLUS | FMT_FLAG_HASH | FMT_FLAG_ZERO;
397 if (fmt_mod != FMT_MOD_NONE) {
398 warn_invalid_length_modifier(pos, fmt_mod, fmt);
401 expected_type = type_wchar_t;
402 allowed_flags = FMT_FLAG_NONE;
406 expected_type = type_int;
408 case FMT_MOD_NONE: expected_type = type_int; break; /* TODO promoted char */
409 case FMT_MOD_l: expected_type = type_wint_t; break;
410 case FMT_MOD_w: expected_type = type_wchar_t; break;
413 warn_invalid_length_modifier(pos, fmt_mod, fmt);
416 allowed_flags = FMT_FLAG_NONE;
420 if (fmt_mod != FMT_MOD_NONE) {
421 warn_invalid_length_modifier(pos, fmt_mod, fmt);
424 expected_type = type_wchar_t_ptr;
425 expected_qual = TYPE_QUALIFIER_CONST;
426 allowed_flags = FMT_FLAG_MINUS;
431 case FMT_MOD_NONE: expected_type = type_char_ptr; break;
432 case FMT_MOD_l: expected_type = type_wchar_t_ptr; break;
433 case FMT_MOD_w: expected_type = type_wchar_t_ptr; break;
436 warn_invalid_length_modifier(pos, fmt_mod, fmt);
439 expected_qual = TYPE_QUALIFIER_CONST;
440 allowed_flags = FMT_FLAG_MINUS;
444 if (fmt_mod != FMT_MOD_NONE) {
445 warn_invalid_length_modifier(pos, fmt_mod, fmt);
448 expected_type = type_void_ptr;
449 allowed_flags = FMT_FLAG_NONE;
454 case FMT_MOD_NONE: expected_type = type_int_ptr; break;
455 case FMT_MOD_hh: expected_type = type_signed_char_ptr; break;
456 case FMT_MOD_h: expected_type = type_short_ptr; break;
457 case FMT_MOD_l: expected_type = type_long_ptr; break;
458 case FMT_MOD_ll: expected_type = type_long_long_ptr; break;
459 case FMT_MOD_j: expected_type = type_intmax_t_ptr; break;
460 case FMT_MOD_z: expected_type = type_ssize_t_ptr; break;
461 case FMT_MOD_t: expected_type = type_ptrdiff_t_ptr; break;
464 warn_invalid_length_modifier(pos, fmt_mod, fmt);
467 allowed_flags = FMT_FLAG_NONE;
471 warningf(pos, "encountered unknown conversion specifier '%%%c' at position %u", fmt, num_fmt);
473 warningf(pos, "too few arguments for format string");
479 format_flags_t wrong_flags = fmt_flags & ~allowed_flags;
480 if (wrong_flags != 0) {
483 if (wrong_flags & FMT_FLAG_HASH) *p++ = '#';
484 if (wrong_flags & FMT_FLAG_ZERO) *p++ = '0';
485 if (wrong_flags & FMT_FLAG_MINUS) *p++ = '-';
486 if (wrong_flags & FMT_FLAG_SPACE) *p++ = ' ';
487 if (wrong_flags & FMT_FLAG_PLUS) *p++ = '+';
488 if (wrong_flags & FMT_FLAG_TICK) *p++ = '\'';
491 warningf(pos, "invalid format flags \"%s\" in conversion specification %%%c at position %u", wrong, fmt, num_fmt);
495 warningf(pos, "too few arguments for format string");
499 { /* create a scope here to prevent warning about the jump to next_arg */
500 type_t *const arg_type = arg->expression->base.type;
501 type_t *const arg_skip = skip_typeref(arg_type);
502 type_t *const expected_type_skip = skip_typeref(expected_type);
505 /* allow any pointer type for %p, not just void */
506 if (is_type_pointer(arg_skip))
510 if (is_type_pointer(expected_type_skip)) {
511 if (is_type_pointer(arg_skip)) {
512 type_t *const exp_to = skip_typeref(expected_type_skip->pointer.points_to);
513 type_t *const arg_to = skip_typeref(arg_skip->pointer.points_to);
514 if ((arg_to->base.qualifiers & ~expected_qual) == 0 &&
515 get_unqualified_type(arg_to) == exp_to) {
519 } else if (get_unqualified_type(arg_skip) == expected_type_skip) {
522 if (is_type_valid(arg_skip)) {
523 warningf(&arg->expression->base.source_position,
524 "argument type '%T' does not match conversion specifier '%%%s%c' at position %u",
525 arg_type, get_length_modifier_name(fmt_mod), (char)fmt, num_fmt);
532 if (c+1 < string + size) {
533 warningf(pos, "format string contains '\\0'");
539 * Check printf-style format.
541 static void check_printf_format(call_argument_t const *arg,
542 format_spec_t const *const spec)
544 /* find format arg */
546 for (; idx < spec->fmt_idx; ++idx) {
552 expression_t const *const fmt_expr = arg->expression;
554 /* find the real args */
555 for (; idx < spec->arg_idx && arg != NULL; ++idx)
558 int const num_fmt = internal_check_printf_format(fmt_expr, arg, spec);
563 for (; arg != NULL; arg = arg->next)
565 if (num_args > (size_t)num_fmt) {
566 warningf(&fmt_expr->base.source_position,
567 "%u argument%s but only %u format specifier%s",
568 num_args, num_args != 1 ? "s" : "",
569 num_fmt, num_fmt != 1 ? "s" : "");
574 * Check scanf-style format.
576 static void check_scanf_format(const call_argument_t *arg,
577 const format_spec_t *spec)
579 /* find format arg */
581 for (; idx < spec->fmt_idx; ++idx) {
587 const expression_t *fmt_expr = arg->expression;
588 if (fmt_expr->kind == EXPR_UNARY_CAST_IMPLICIT) {
589 fmt_expr = fmt_expr->unary.value;
592 if (fmt_expr->kind != EXPR_STRING_LITERAL
593 && fmt_expr->kind != EXPR_WIDE_STRING_LITERAL)
596 const char *string = fmt_expr->literal.value.begin;
597 size_t size = fmt_expr->literal.value.size;
598 const char *c = string;
600 /* find the real args */
601 for (; idx < spec->arg_idx && arg != NULL; ++idx)
604 const source_position_t *pos = &fmt_expr->base.source_position;
605 unsigned num_fmt = 0;
607 for (fmt = *c; fmt != '\0'; fmt = *(++c)) {
612 warningf(pos, "dangling '%%' in format string");
620 /* look for length modifiers */
621 format_length_modifier_t fmt_mod = FMT_MOD_NONE;
627 fmt_mod = FMT_MOD_hh;
637 fmt_mod = FMT_MOD_ll;
643 case 'L': fmt = *(++c); fmt_mod = FMT_MOD_L; break;
644 case 'j': fmt = *(++c); fmt_mod = FMT_MOD_j; break;
645 case 't': fmt = *(++c); fmt_mod = FMT_MOD_t; break;
646 case 'z': fmt = *(++c); fmt_mod = FMT_MOD_z; break;
662 fmt_mod = FMT_MOD_I32;
667 } else if (fmt == '6') {
671 fmt_mod = FMT_MOD_I64;
682 warningf(pos, "dangling % with conversion specififer in format string");
686 type_t *expected_type;
691 case FMT_MOD_NONE: expected_type = type_int; break;
692 case FMT_MOD_hh: expected_type = type_signed_char; break;
693 case FMT_MOD_h: expected_type = type_short; break;
694 case FMT_MOD_l: expected_type = type_long; break;
695 case FMT_MOD_ll: expected_type = type_long_long; break;
696 case FMT_MOD_j: expected_type = type_intmax_t; break;
697 case FMT_MOD_z: expected_type = type_ssize_t; break;
698 case FMT_MOD_t: expected_type = type_ptrdiff_t; break;
699 case FMT_MOD_I: expected_type = type_ptrdiff_t; break;
700 case FMT_MOD_I32: expected_type = type_int32; break;
701 case FMT_MOD_I64: expected_type = type_int64; break;
704 warn_invalid_length_modifier(pos, fmt_mod, fmt);
714 case FMT_MOD_NONE: expected_type = type_unsigned_int; break;
715 case FMT_MOD_hh: expected_type = type_unsigned_char; break;
716 case FMT_MOD_h: expected_type = type_unsigned_short; break;
717 case FMT_MOD_l: expected_type = type_unsigned_long; break;
718 case FMT_MOD_ll: expected_type = type_unsigned_long_long; break;
719 case FMT_MOD_j: expected_type = type_uintmax_t; break;
720 case FMT_MOD_z: expected_type = type_size_t; break;
721 case FMT_MOD_t: expected_type = type_uptrdiff_t; break;
722 case FMT_MOD_I: expected_type = type_size_t; break;
723 case FMT_MOD_I32: expected_type = type_unsigned_int32; break;
724 case FMT_MOD_I64: expected_type = type_unsigned_int64; break;
727 warn_invalid_length_modifier(pos, fmt_mod, fmt);
741 case FMT_MOD_l: expected_type = type_double; break;
742 case FMT_MOD_NONE: expected_type = type_float; break;
743 case FMT_MOD_L: expected_type = type_long_double; break;
746 warn_invalid_length_modifier(pos, fmt_mod, fmt);
752 if (fmt_mod != FMT_MOD_NONE) {
753 warn_invalid_length_modifier(pos, fmt_mod, fmt);
756 expected_type = type_wchar_t;
760 expected_type = type_int;
762 case FMT_MOD_NONE: expected_type = type_int; break; /* TODO promoted char */
763 case FMT_MOD_l: expected_type = type_wint_t; break;
764 case FMT_MOD_w: expected_type = type_wchar_t; break;
767 warn_invalid_length_modifier(pos, fmt_mod, fmt);
773 if (fmt_mod != FMT_MOD_NONE) {
774 warn_invalid_length_modifier(pos, fmt_mod, fmt);
777 expected_type = type_wchar_t;
783 case FMT_MOD_NONE: expected_type = type_char; break;
784 case FMT_MOD_l: expected_type = type_wchar_t; break;
785 case FMT_MOD_w: expected_type = type_wchar_t; break;
788 warn_invalid_length_modifier(pos, fmt_mod, fmt);
794 if (fmt_mod != FMT_MOD_NONE) {
795 warn_invalid_length_modifier(pos, fmt_mod, fmt);
798 expected_type = type_void_ptr;
803 case FMT_MOD_NONE: expected_type = type_int; break;
804 case FMT_MOD_hh: expected_type = type_signed_char; break;
805 case FMT_MOD_h: expected_type = type_short; break;
806 case FMT_MOD_l: expected_type = type_long; break;
807 case FMT_MOD_ll: expected_type = type_long_long; break;
808 case FMT_MOD_j: expected_type = type_intmax_t; break;
809 case FMT_MOD_z: expected_type = type_ssize_t; break;
810 case FMT_MOD_t: expected_type = type_ptrdiff_t; break;
813 warn_invalid_length_modifier(pos, fmt_mod, fmt);
819 warningf(pos, "encountered unknown conversion specifier '%%%c' at format %u",
822 warningf(pos, "too few arguments for format string");
829 warningf(pos, "too few arguments for format string");
833 { /* create a scope here to prevent warning about the jump to next_arg */
834 type_t *const arg_type = arg->expression->base.type;
835 type_t *const arg_skip = skip_typeref(arg_type);
836 type_t *const expected_type_skip = skip_typeref(expected_type);
838 if (! is_type_pointer(arg_skip))
840 type_t *const ptr_skip = skip_typeref(arg_skip->pointer.points_to);
843 /* allow any pointer type for %p, not just void */
844 if (is_type_pointer(ptr_skip))
848 /* do NOT allow const or restrict, all other should be ok */
849 if (ptr_skip->base.qualifiers & (TYPE_QUALIFIER_CONST | TYPE_QUALIFIER_VOLATILE))
851 type_t *const unqual_ptr = get_unqualified_type(ptr_skip);
852 if (unqual_ptr == expected_type_skip) {
854 } else if (expected_type_skip == type_char) {
855 /* char matches with unsigned char AND signed char */
856 if (unqual_ptr == type_signed_char || unqual_ptr == type_unsigned_char)
860 if (is_type_valid(arg_skip)) {
861 warningf(&arg->expression->base.source_position,
862 "argument type '%T' does not match conversion specifier '%%%s%c' at position %u",
863 arg_type, get_length_modifier_name(fmt_mod), (char)fmt, num_fmt);
870 if (c+1 < string + size) {
871 warningf(pos, "format string contains '\\0'");
874 unsigned num_args = num_fmt;
875 while (arg != NULL) {
879 warningf(pos, "%u argument%s but only %u format specifier%s",
880 num_args, num_args != 1 ? "s" : "",
881 num_fmt, num_fmt != 1 ? "s" : "");
885 static const format_spec_t builtin_table[] = {
886 { "printf", FORMAT_PRINTF, 0, 1 },
887 { "wprintf", FORMAT_PRINTF, 0, 1 },
888 { "sprintf", FORMAT_PRINTF, 1, 2 },
889 { "swprintf", FORMAT_PRINTF, 1, 2 },
890 { "snprintf", FORMAT_PRINTF, 2, 3 },
891 { "snwprintf", FORMAT_PRINTF, 2, 3 },
892 { "fprintf", FORMAT_PRINTF, 1, 2 },
893 { "fwprintf", FORMAT_PRINTF, 1, 2 },
894 { "snwprintf", FORMAT_PRINTF, 2, 3 },
895 { "snwprintf", FORMAT_PRINTF, 2, 3 },
897 { "scanf", FORMAT_SCANF, 0, 1 },
898 { "wscanf", FORMAT_SCANF, 0, 1 },
899 { "sscanf", FORMAT_SCANF, 1, 2 },
900 { "swscanf", FORMAT_SCANF, 1, 2 },
901 { "fscanf", FORMAT_SCANF, 1, 2 },
902 { "fwscanf", FORMAT_SCANF, 1, 2 },
904 { "strftime", FORMAT_STRFTIME, 3, 4 },
905 { "wcstrftime", FORMAT_STRFTIME, 3, 4 },
907 { "strfmon", FORMAT_STRFMON, 3, 4 },
910 { "_snprintf", FORMAT_PRINTF, 2, 3 },
911 { "_snwprintf", FORMAT_PRINTF, 2, 3 },
912 { "_scrintf", FORMAT_PRINTF, 0, 1 },
913 { "_scwprintf", FORMAT_PRINTF, 0, 1 },
914 { "printf_s", FORMAT_PRINTF, 0, 1 },
915 { "wprintf_s", FORMAT_PRINTF, 0, 1 },
916 { "sprintf_s", FORMAT_PRINTF, 3, 4 },
917 { "swprintf_s", FORMAT_PRINTF, 3, 4 },
918 { "fprintf_s", FORMAT_PRINTF, 1, 2 },
919 { "fwprintf_s", FORMAT_PRINTF, 1, 2 },
920 { "_sprintf_l", FORMAT_PRINTF, 1, 3 },
921 { "_swprintf_l", FORMAT_PRINTF, 1, 3 },
922 { "_printf_l", FORMAT_PRINTF, 0, 2 },
923 { "_wprintf_l", FORMAT_PRINTF, 0, 2 },
924 { "_fprintf_l", FORMAT_PRINTF, 1, 3 },
925 { "_fwprintf_l", FORMAT_PRINTF, 1, 3 },
926 { "_printf_s_l", FORMAT_PRINTF, 0, 2 },
927 { "_wprintf_s_l", FORMAT_PRINTF, 0, 2 },
928 { "_sprintf_s_l", FORMAT_PRINTF, 3, 5 },
929 { "_swprintf_s_l", FORMAT_PRINTF, 3, 5 },
930 { "_fprintf_s_l", FORMAT_PRINTF, 1, 3 },
931 { "_fwprintf_s_l", FORMAT_PRINTF, 1, 3 },
934 void check_format(const call_expression_t *const call)
939 const expression_t *const func_expr = call->function;
940 if (func_expr->kind != EXPR_REFERENCE)
943 const entity_t *const entity = func_expr->reference.entity;
944 const call_argument_t * arg = call->arguments;
947 /* the declaration has a GNU format attribute, check it */
950 * For some functions we always check the format, even if it was not
951 * specified. This allows to check format even in MS mode or without
954 const char *const name = entity->base.symbol->string;
955 for (size_t i = 0; i < lengthof(builtin_table); ++i) {
956 if (strcmp(name, builtin_table[i].name) == 0) {
957 switch (builtin_table[i].fmt_kind) {
959 check_printf_format(arg, &builtin_table[i]);
962 check_scanf_format(arg, &builtin_table[i]);
964 case FORMAT_STRFTIME:
966 /* TODO: implement other cases */