[cfe-commits] r146367 - in /cfe/trunk: include/clang/Basic/Builtins.def test/Sema/format-strings-scanf.c

Anna Zaks ganna at apple.com
Mon Dec 12 10:15:56 PST 2011


Great! See a couple of comments below.

Thanks,
Anna.
On Dec 12, 2011, at 2:34 AM, Hans Wennborg wrote:

> Author: hans
> Date: Mon Dec 12 04:34:18 2011
> New Revision: 146367
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=146367&view=rev
> Log:
> Make fscanf, vscanf, etc. be recognized as scanf-like functions.
> 
> Modified:
>    cfe/trunk/include/clang/Basic/Builtins.def
>    cfe/trunk/test/Sema/format-strings-scanf.c
>
> Modified: cfe/trunk/test/Sema/format-strings-scanf.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/format-strings-scanf.c?rev=146367&r1=146366&r2=146367&view=diff
> ==============================================================================
> --- cfe/trunk/test/Sema/format-strings-scanf.c (original)
> +++ cfe/trunk/test/Sema/format-strings-scanf.c Mon Dec 12 04:34:18 2011
> @@ -1,12 +1,18 @@
> // RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral %s
> 
> +#include <stdarg.h>

Is it possible to fake the header inclusion here? 

> typedef __typeof(sizeof(int)) size_t;
> typedef struct _FILE FILE;
> typedef __WCHAR_TYPE__ wchar_t;
> 
> int fscanf(FILE * restrict, const char * restrict, ...) ;
> int scanf(const char * restrict, ...) ;
> -int sscanf(const char * restrict, const char * restrict, ...) ;
> +int sscanf(char * restrict, const char * restrict, ...) ;

Why the change of the signature here? Shouldn't the first parameter be of type 'const char *restrict' (same for vsscanf below)?

> +int my_scanf(const char * restrict, ...) __attribute__((__format__(__scanf__, 1, 2)));
> +
> +int vscanf(const char * restrict, va_list);
> +int vfscanf(FILE * restrict, const char * restrict, va_list);
> +int vsscanf(char * restrict, const char * restrict, va_list);
> 
> void test(const char *s, int *i) {
>   scanf(s, i); // expected-warning{{ormat string is not a string literal}}
> @@ -45,3 +51,19 @@
>   scanf(kFormat2, str); // expected-warning{{no closing ']' for '%[' in scanf format string}}
>   scanf("%[", str); // expected-warning{{no closing ']' for '%[' in scanf format string}}
> }
> +
> +void test_variants(int *i, const char *s, ...) {
> +  FILE *f = 0;
> +  char buf[100];
> +
> +  fscanf(f, "%ld", i); // expected-warning{{conversion specifies type 'long *' but the argument has type 'int *'}}
> +  sscanf(buf, "%ld", i); // expected-warning{{conversion specifies type 'long *' but the argument has type 'int *'}}
> +  my_scanf("%ld", i); // expected-warning{{conversion specifies type 'long *' but the argument has type 'int *'}}
> +
> +  va_list ap;
> +  va_start(ap, s);
> +
> +  vscanf("%[abc", ap); // expected-warning{{no closing ']' for '%[' in scanf format string}}
> +  vfscanf(f, "%[abc", ap); // expected-warning{{no closing ']' for '%[' in scanf format string}}
> +  vsscanf(buf, "%[abc", ap); // expected-warning{{no closing ']' for '%[' in scanf format string}}
> +}
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits





More information about the cfe-commits mailing list