mirror of
https://github.com/Gericom/teak-llvm.git
synced 2025-06-19 11:35:51 -04:00

The array will decay into a pointer, creating an unexpected result. sizeof(array + int) is an easy to make typo for sizeof(array) + int. This was motivated by a NetBSD security bug, used sizeof(key - r) instead of sizeof(key) - r, reducing entropy in a random number generator. http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/kern/subr_cprng.c.diff?r1=1.14&r2=1.15&only_with_tag=MAIN&f=h Differential Revision: http://llvm-reviews.chandlerc.com/D571 llvm-svn: 178371
19 lines
853 B
C
19 lines
853 B
C
// RUN: %clang_cc1 -fsyntax-only -verify %s
|
|
|
|
void f(int x) {
|
|
char foo[10];
|
|
int bar[20];
|
|
char qux[30];
|
|
|
|
(void)sizeof(bar + 10); // expected-warning{{sizeof on pointer operation will return size of 'int *' instead of 'int [20]'}}
|
|
(void)sizeof(foo - 20); // expected-warning{{sizeof on pointer operation will return size of 'char *' instead of 'char [10]'}}
|
|
(void)sizeof(bar - x); // expected-warning{{sizeof on pointer operation will return size of 'int *' instead of 'int [20]'}}
|
|
(void)sizeof(foo + x); // expected-warning{{sizeof on pointer operation will return size of 'char *' instead of 'char [10]'}}
|
|
|
|
// This is ptrdiff_t.
|
|
(void)sizeof(foo - qux); // no-warning
|
|
|
|
(void)sizeof(foo, x); // no-warning
|
|
(void)sizeof(x, foo); // expected-warning{{sizeof on pointer operation will return size of 'char *' instead of 'char [10]'}}
|
|
}
|