12fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert/* 22fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert * Copyright (C) 2014 The Android Open Source Project 32fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert * 42fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert * Licensed under the Apache License, Version 2.0 (the "License"); 52fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert * you may not use this file except in compliance with the License. 62fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert * You may obtain a copy of the License at 72fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert * 82fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert * http://www.apache.org/licenses/LICENSE-2.0 92fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert * 102fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert * Unless required by applicable law or agreed to in writing, software 112fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert * distributed under the License is distributed on an "AS IS" BASIS, 122fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 132fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert * See the License for the specific language governing permissions and 142fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert * limitations under the License. 152fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert */ 162fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert 172fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert#undef _FORTIFY_SOURCE 182fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert#define _FORTIFY_SOURCE 2 1920f2268d61966230587957912491b67ad8bb91c8Yabin Cui#include <fcntl.h> 2020f2268d61966230587957912491b67ad8bb91c8Yabin Cui#include <netinet/in.h> 2120f2268d61966230587957912491b67ad8bb91c8Yabin Cui#include <poll.h> 2220f2268d61966230587957912491b67ad8bb91c8Yabin Cui#include <stdarg.h> 232fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert#include <stdio.h> 2420f2268d61966230587957912491b67ad8bb91c8Yabin Cui#include <string.h> 2520f2268d61966230587957912491b67ad8bb91c8Yabin Cui#include <sys/socket.h> 2620f2268d61966230587957912491b67ad8bb91c8Yabin Cui#include <sys/stat.h> 2720f2268d61966230587957912491b67ad8bb91c8Yabin Cui#include <time.h> 2820f2268d61966230587957912491b67ad8bb91c8Yabin Cui#include <unistd.h> 292fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert 302fbb1b653ee46b6dee715ae7c085f094f505390dDan Albertvoid test_sprintf() { 312fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert char buf[4]; 322fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert 332fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert // NOLINTNEXTLINE(whitespace/line_length) 34b4b15c63a17e74f5f6229f7b8ed034cf72e52cf4Elliott Hughes // GCC: warning: call to int __builtin___sprintf_chk(char*, int, {{(long )?}}unsigned int, const char*, ...) will always overflow destination buffer 352fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert // clang should emit a warning, but doesn't 3620f2268d61966230587957912491b67ad8bb91c8Yabin Cui sprintf(buf, "foobar"); // NOLINT(runtime/printf) 372fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert 382fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert // NOLINTNEXTLINE(whitespace/line_length) 39b4b15c63a17e74f5f6229f7b8ed034cf72e52cf4Elliott Hughes // GCC: warning: call to int __builtin___sprintf_chk(char*, int, {{(long )?}}unsigned int, const char*, ...) will always overflow destination buffer 402fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert // clang should emit a warning, but doesn't 4120f2268d61966230587957912491b67ad8bb91c8Yabin Cui sprintf(buf, "%s", "foobar"); // NOLINT(runtime/printf) 422fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert} 432fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert 442fbb1b653ee46b6dee715ae7c085f094f505390dDan Albertvoid test_snprintf() { 452fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert char buf[4]; 462fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert 472fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert // NOLINTNEXTLINE(whitespace/line_length) 48b4b15c63a17e74f5f6229f7b8ed034cf72e52cf4Elliott Hughes // GCC: warning: call to int __builtin___snprintf_chk(char*, {{(long )?}}unsigned int, int, {{(long )?}}unsigned int, const char*, ...) will always overflow destination buffer 492fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert // clang should emit a warning, but doesn't 5020f2268d61966230587957912491b67ad8bb91c8Yabin Cui snprintf(buf, 5, "foobar"); // NOLINT(runtime/printf) 512fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert 522fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert // NOLINTNEXTLINE(whitespace/line_length) 53b4b15c63a17e74f5f6229f7b8ed034cf72e52cf4Elliott Hughes // GCC: warning: call to int __builtin___snprintf_chk(char*, {{(long )?}}unsigned int, int, {{(long )?}}unsigned int, const char*, ...) will always overflow destination buffer 542fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert // clang should emit a warning, but doesn't 5520f2268d61966230587957912491b67ad8bb91c8Yabin Cui snprintf(buf, 5, "%s", "foobar"); // NOLINT(runtime/printf) 562fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert 572fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert // NOLINTNEXTLINE(whitespace/line_length) 58b4b15c63a17e74f5f6229f7b8ed034cf72e52cf4Elliott Hughes // GCC: warning: call to int __builtin___snprintf_chk(char*, {{(long )?}}unsigned int, int, {{(long )?}}unsigned int, const char*, ...) will always overflow destination buffer 592fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert // clang should emit a warning, but doesn't 6020f2268d61966230587957912491b67ad8bb91c8Yabin Cui snprintf(buf, 5, " %s ", "foobar"); // NOLINT(runtime/printf) 612fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert 622fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert // NOLINTNEXTLINE(whitespace/line_length) 63b4b15c63a17e74f5f6229f7b8ed034cf72e52cf4Elliott Hughes // GCC: warning: call to int __builtin___snprintf_chk(char*, {{(long )?}}unsigned int, int, {{(long )?}}unsigned int, const char*, ...) will always overflow destination buffer 642fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert // clang should emit a warning, but doesn't 6520f2268d61966230587957912491b67ad8bb91c8Yabin Cui snprintf(buf, 5, "%d", 100000); // NOLINT(runtime/printf) 6620f2268d61966230587957912491b67ad8bb91c8Yabin Cui} 6720f2268d61966230587957912491b67ad8bb91c8Yabin Cui 6820f2268d61966230587957912491b67ad8bb91c8Yabin Cuivoid test_memcpy() { 6920f2268d61966230587957912491b67ad8bb91c8Yabin Cui char buf[4]; 7020f2268d61966230587957912491b67ad8bb91c8Yabin Cui 7120f2268d61966230587957912491b67ad8bb91c8Yabin Cui // NOLINTNEXTLINE(whitespace/line_length) 7220f2268d61966230587957912491b67ad8bb91c8Yabin Cui // GCC: warning: call to void* __builtin___memcpy_chk(void*, const void*, {{(long )?}}unsigned int, {{(long )?}}unsigned int) will always overflow destination buffer 7320f2268d61966230587957912491b67ad8bb91c8Yabin Cui // clang should emit a warning, but doesn't 7420f2268d61966230587957912491b67ad8bb91c8Yabin Cui memcpy(buf, "foobar", sizeof("foobar")); 7520f2268d61966230587957912491b67ad8bb91c8Yabin Cui} 7620f2268d61966230587957912491b67ad8bb91c8Yabin Cui 7720f2268d61966230587957912491b67ad8bb91c8Yabin Cuivoid test_memmove() { 7820f2268d61966230587957912491b67ad8bb91c8Yabin Cui char buf[4]; 7920f2268d61966230587957912491b67ad8bb91c8Yabin Cui 8020f2268d61966230587957912491b67ad8bb91c8Yabin Cui // NOLINTNEXTLINE(whitespace/line_length) 8120f2268d61966230587957912491b67ad8bb91c8Yabin Cui // GCC: warning: call to void* __builtin___memmove_chk(void*, const void*, {{(long )?}}unsigned int, {{(long )?}}unsigned int) will always overflow destination buffer 8220f2268d61966230587957912491b67ad8bb91c8Yabin Cui // clang should emit a warning, but doesn't 8320f2268d61966230587957912491b67ad8bb91c8Yabin Cui memmove(buf, "foobar", sizeof("foobar")); 8420f2268d61966230587957912491b67ad8bb91c8Yabin Cui} 8520f2268d61966230587957912491b67ad8bb91c8Yabin Cui 8620f2268d61966230587957912491b67ad8bb91c8Yabin Cuivoid test_memset() { 8720f2268d61966230587957912491b67ad8bb91c8Yabin Cui char buf[4]; 8820f2268d61966230587957912491b67ad8bb91c8Yabin Cui 8920f2268d61966230587957912491b67ad8bb91c8Yabin Cui // NOLINTNEXTLINE(whitespace/line_length) 9020f2268d61966230587957912491b67ad8bb91c8Yabin Cui // GCC: warning: call to void* __builtin___memset_chk(void*, int, {{(long )?}}unsigned int, {{(long )?}}unsigned int) will always overflow destination buffer 9120f2268d61966230587957912491b67ad8bb91c8Yabin Cui // clang should emit a warning, but doesn't 9220f2268d61966230587957912491b67ad8bb91c8Yabin Cui memset(buf, 0, 6); 9320f2268d61966230587957912491b67ad8bb91c8Yabin Cui} 9420f2268d61966230587957912491b67ad8bb91c8Yabin Cui 9520f2268d61966230587957912491b67ad8bb91c8Yabin Cuivoid test_strcpy() { 9620f2268d61966230587957912491b67ad8bb91c8Yabin Cui char buf[4]; 9720f2268d61966230587957912491b67ad8bb91c8Yabin Cui 9820f2268d61966230587957912491b67ad8bb91c8Yabin Cui // NOLINTNEXTLINE(whitespace/line_length) 99f3bd305b8f8270f157ee79851fc630abd94d3245Yabin Cui // GCC: warning: call to {{(char\* __builtin___strcpy_chk\(char\*, const char\*, unsigned int\))|(void\* __builtin___memcpy_chk\(void\*, const void\*, (long )?unsigned int, (long )?unsigned int\))}} will always overflow destination buffer 10020f2268d61966230587957912491b67ad8bb91c8Yabin Cui // clang should emit a warning, but doesn't 10120f2268d61966230587957912491b67ad8bb91c8Yabin Cui strcpy(buf, "foobar"); // NOLINT(runtime/printf) 10220f2268d61966230587957912491b67ad8bb91c8Yabin Cui} 10320f2268d61966230587957912491b67ad8bb91c8Yabin Cui 10420f2268d61966230587957912491b67ad8bb91c8Yabin Cuivoid test_stpcpy() { 10520f2268d61966230587957912491b67ad8bb91c8Yabin Cui char buf[4]; 10620f2268d61966230587957912491b67ad8bb91c8Yabin Cui 10720f2268d61966230587957912491b67ad8bb91c8Yabin Cui // NOLINTNEXTLINE(whitespace/line_length) 10820f2268d61966230587957912491b67ad8bb91c8Yabin Cui // GCC: warning: call to char* __builtin___stpcpy_chk(char*, const char*, {{(long )?}}unsigned int) will always overflow destination buffer 10920f2268d61966230587957912491b67ad8bb91c8Yabin Cui // clang should emit a warning, but doesn't 11020f2268d61966230587957912491b67ad8bb91c8Yabin Cui stpcpy(buf, "foobar"); 11120f2268d61966230587957912491b67ad8bb91c8Yabin Cui} 11220f2268d61966230587957912491b67ad8bb91c8Yabin Cui 11320f2268d61966230587957912491b67ad8bb91c8Yabin Cuivoid test_strncpy() { 11420f2268d61966230587957912491b67ad8bb91c8Yabin Cui char buf[4]; 11520f2268d61966230587957912491b67ad8bb91c8Yabin Cui 11620f2268d61966230587957912491b67ad8bb91c8Yabin Cui // NOLINTNEXTLINE(whitespace/line_length) 11720f2268d61966230587957912491b67ad8bb91c8Yabin Cui // GCC: warning: call to char* __builtin___strncpy_chk(char*, const char*, {{(long )?}}unsigned int, {{(long )?}}unsigned int) will always overflow destination buffer 11820f2268d61966230587957912491b67ad8bb91c8Yabin Cui // clang should emit a warning, but doesn't 11920f2268d61966230587957912491b67ad8bb91c8Yabin Cui strncpy(buf, "foobar", sizeof("foobar")); 12020f2268d61966230587957912491b67ad8bb91c8Yabin Cui} 12120f2268d61966230587957912491b67ad8bb91c8Yabin Cui 12220f2268d61966230587957912491b67ad8bb91c8Yabin Cuivoid test_strcat() { 12320f2268d61966230587957912491b67ad8bb91c8Yabin Cui char buf[4] = ""; 12420f2268d61966230587957912491b67ad8bb91c8Yabin Cui 12520f2268d61966230587957912491b67ad8bb91c8Yabin Cui // NOLINTNEXTLINE(whitespace/line_length) 126f3bd305b8f8270f157ee79851fc630abd94d3245Yabin Cui // GCC: warning: call to {{(char\* __builtin___strcat_chk\(char\*, const char\*, unsigned int\))|(void\* __builtin___memcpy_chk\(void\*, const void\*, (long )?unsigned int, (long )?unsigned int\))}} will always overflow destination buffer 12720f2268d61966230587957912491b67ad8bb91c8Yabin Cui // clang should emit a warning, but doesn't 12820f2268d61966230587957912491b67ad8bb91c8Yabin Cui strcat(buf, "foobar"); // NOLINT(runtime/printf) 12920f2268d61966230587957912491b67ad8bb91c8Yabin Cui} 13020f2268d61966230587957912491b67ad8bb91c8Yabin Cui 13120f2268d61966230587957912491b67ad8bb91c8Yabin Cuivoid test_strncat() { 13220f2268d61966230587957912491b67ad8bb91c8Yabin Cui char buf[4] = ""; 13320f2268d61966230587957912491b67ad8bb91c8Yabin Cui 13420f2268d61966230587957912491b67ad8bb91c8Yabin Cui // NOLINTNEXTLINE(whitespace/line_length) 135f3bd305b8f8270f157ee79851fc630abd94d3245Yabin Cui // GCC: warning: call to {{(char\* __builtin___strcat_chk\(char\*, const char\*, unsigned int\))|(void\* __builtin___memcpy_chk\(void\*, const void\*, (long )?unsigned int, (long )?unsigned int\))}} will always overflow destination buffer 13620f2268d61966230587957912491b67ad8bb91c8Yabin Cui // gcc output warning with __builtin___strcat_chk for __builtin___strncat_chk. 13720f2268d61966230587957912491b67ad8bb91c8Yabin Cui // clang should emit a warning, but doesn't 13820f2268d61966230587957912491b67ad8bb91c8Yabin Cui strncat(buf, "foobar", sizeof("foobar")); 13920f2268d61966230587957912491b67ad8bb91c8Yabin Cui} 14020f2268d61966230587957912491b67ad8bb91c8Yabin Cui 14120f2268d61966230587957912491b67ad8bb91c8Yabin Cuivoid test_vsprintf(const char* fmt, ...) { 14220f2268d61966230587957912491b67ad8bb91c8Yabin Cui va_list va; 14320f2268d61966230587957912491b67ad8bb91c8Yabin Cui char buf[4]; 14420f2268d61966230587957912491b67ad8bb91c8Yabin Cui va_start(va, fmt); 14520f2268d61966230587957912491b67ad8bb91c8Yabin Cui 14620f2268d61966230587957912491b67ad8bb91c8Yabin Cui // NOLINTNEXTLINE(whitespace/line_length) 147d9647594dee6fc0352845904f2249b7f1c4e2364Yabin Cui // GCC: warning: call to int __builtin___vsprintf_chk(char*, int, {{(long )?}}unsigned int, const char*, {{(__va_list)|(void\*)|(char\*)|(__va_list_tag\*)}}) will always overflow destination buffer 14820f2268d61966230587957912491b67ad8bb91c8Yabin Cui // clang should emit a warning, but doesn't 14920f2268d61966230587957912491b67ad8bb91c8Yabin Cui vsprintf(buf, "foobar", va); 15020f2268d61966230587957912491b67ad8bb91c8Yabin Cui va_end(va); 15120f2268d61966230587957912491b67ad8bb91c8Yabin Cui} 15220f2268d61966230587957912491b67ad8bb91c8Yabin Cui 15320f2268d61966230587957912491b67ad8bb91c8Yabin Cuivoid test_vsnprintf(const char* fmt, ...) { 15420f2268d61966230587957912491b67ad8bb91c8Yabin Cui va_list va; 15520f2268d61966230587957912491b67ad8bb91c8Yabin Cui char buf[4]; 15620f2268d61966230587957912491b67ad8bb91c8Yabin Cui va_start(va, fmt); 15720f2268d61966230587957912491b67ad8bb91c8Yabin Cui 15820f2268d61966230587957912491b67ad8bb91c8Yabin Cui // NOLINTNEXTLINE(whitespace/line_length) 159d9647594dee6fc0352845904f2249b7f1c4e2364Yabin Cui // GCC: warning: call to int __builtin___vsnprintf_chk(char*, {{(long )?}}unsigned int, int, {{(long )?}}unsigned int, const char*, {{(__va_list)|(void\*)|(char\*)|(__va_list_tag\*)}}) will always overflow destination buffer 16020f2268d61966230587957912491b67ad8bb91c8Yabin Cui // clang should emit a warning, but doesn't 16120f2268d61966230587957912491b67ad8bb91c8Yabin Cui vsnprintf(buf, 5, "foobar", va); // NOLINT(runtime/printf) 16220f2268d61966230587957912491b67ad8bb91c8Yabin Cui 16320f2268d61966230587957912491b67ad8bb91c8Yabin Cui va_end(va); 16420f2268d61966230587957912491b67ad8bb91c8Yabin Cui} 16520f2268d61966230587957912491b67ad8bb91c8Yabin Cui 16620f2268d61966230587957912491b67ad8bb91c8Yabin Cuivoid test_fgets() { 16720f2268d61966230587957912491b67ad8bb91c8Yabin Cui char buf[4]; 16820f2268d61966230587957912491b67ad8bb91c8Yabin Cui 16920f2268d61966230587957912491b67ad8bb91c8Yabin Cui // NOLINTNEXTLINE(whitespace/line_length) 17020f2268d61966230587957912491b67ad8bb91c8Yabin Cui // GCC: error: call to '__fgets_too_small_error' declared with attribute error: fgets called with size less than zero 17120f2268d61966230587957912491b67ad8bb91c8Yabin Cui // clang should emit a warning, but doesn't 17220f2268d61966230587957912491b67ad8bb91c8Yabin Cui fgets(buf, -1, stdin); 17320f2268d61966230587957912491b67ad8bb91c8Yabin Cui 17420f2268d61966230587957912491b67ad8bb91c8Yabin Cui // NOLINTNEXTLINE(whitespace/line_length) 17520f2268d61966230587957912491b67ad8bb91c8Yabin Cui // GCC: error: call to '__fgets_too_big_error' declared with attribute error: fgets called with size bigger than buffer 17620f2268d61966230587957912491b67ad8bb91c8Yabin Cui // clang should emit a warning, but doesn't 17720f2268d61966230587957912491b67ad8bb91c8Yabin Cui fgets(buf, 6, stdin); 17820f2268d61966230587957912491b67ad8bb91c8Yabin Cui} 17920f2268d61966230587957912491b67ad8bb91c8Yabin Cui 18020f2268d61966230587957912491b67ad8bb91c8Yabin Cuivoid test_recvfrom() { 18120f2268d61966230587957912491b67ad8bb91c8Yabin Cui char buf[4]; 18220f2268d61966230587957912491b67ad8bb91c8Yabin Cui sockaddr_in addr; 18320f2268d61966230587957912491b67ad8bb91c8Yabin Cui 18420f2268d61966230587957912491b67ad8bb91c8Yabin Cui // NOLINTNEXTLINE(whitespace/line_length) 18520f2268d61966230587957912491b67ad8bb91c8Yabin Cui // GCC: error: call to '__recvfrom_error' declared with attribute error: recvfrom called with size bigger than buffer 18620f2268d61966230587957912491b67ad8bb91c8Yabin Cui // clang should emit a warning, but doesn't 18720f2268d61966230587957912491b67ad8bb91c8Yabin Cui recvfrom(0, buf, 6, 0, reinterpret_cast<sockaddr*>(&addr), NULL); 18820f2268d61966230587957912491b67ad8bb91c8Yabin Cui} 18920f2268d61966230587957912491b67ad8bb91c8Yabin Cui 19020f2268d61966230587957912491b67ad8bb91c8Yabin Cuivoid test_umask() { 19120f2268d61966230587957912491b67ad8bb91c8Yabin Cui // NOLINTNEXTLINE(whitespace/line_length) 19220f2268d61966230587957912491b67ad8bb91c8Yabin Cui // GCC: error: call to '__umask_invalid_mode' declared with attribute error: umask called with invalid mode 19320f2268d61966230587957912491b67ad8bb91c8Yabin Cui // clang should emit a warning, but doesn't 19420f2268d61966230587957912491b67ad8bb91c8Yabin Cui umask(01777); 19520f2268d61966230587957912491b67ad8bb91c8Yabin Cui} 19620f2268d61966230587957912491b67ad8bb91c8Yabin Cui 19720f2268d61966230587957912491b67ad8bb91c8Yabin Cuivoid test_read() { 19820f2268d61966230587957912491b67ad8bb91c8Yabin Cui char buf[4]; 19920f2268d61966230587957912491b67ad8bb91c8Yabin Cui // NOLINTNEXTLINE(whitespace/line_length) 20020f2268d61966230587957912491b67ad8bb91c8Yabin Cui // GCC: error: call to '__read_dest_size_error' declared with attribute error: read called with size bigger than destination 20120f2268d61966230587957912491b67ad8bb91c8Yabin Cui // clang should emit a warning, but doesn't 20220f2268d61966230587957912491b67ad8bb91c8Yabin Cui read(0, buf, 6); 20320f2268d61966230587957912491b67ad8bb91c8Yabin Cui} 20420f2268d61966230587957912491b67ad8bb91c8Yabin Cui 20520f2268d61966230587957912491b67ad8bb91c8Yabin Cuivoid test_open() { 20620f2268d61966230587957912491b67ad8bb91c8Yabin Cui // NOLINTNEXTLINE(whitespace/line_length) 20720f2268d61966230587957912491b67ad8bb91c8Yabin Cui // GCC: error: call to '__creat_missing_mode' declared with attribute error: called with O_CREAT, but missing mode 20820f2268d61966230587957912491b67ad8bb91c8Yabin Cui // clang should emit a warning, but doesn't 20920f2268d61966230587957912491b67ad8bb91c8Yabin Cui open("/dev/null", O_CREAT); 21020f2268d61966230587957912491b67ad8bb91c8Yabin Cui 21120f2268d61966230587957912491b67ad8bb91c8Yabin Cui // NOLINTNEXTLINE(whitespace/line_length) 21220f2268d61966230587957912491b67ad8bb91c8Yabin Cui // GCC: error: call to '__creat_too_many_args' declared with attribute error: too many arguments 21320f2268d61966230587957912491b67ad8bb91c8Yabin Cui // clang should emit a warning, but doesn't 21420f2268d61966230587957912491b67ad8bb91c8Yabin Cui open("/dev/null", O_CREAT, 0, 0); 21520f2268d61966230587957912491b67ad8bb91c8Yabin Cui} 21620f2268d61966230587957912491b67ad8bb91c8Yabin Cui 21720f2268d61966230587957912491b67ad8bb91c8Yabin Cuivoid test_poll() { 21820f2268d61966230587957912491b67ad8bb91c8Yabin Cui pollfd fds[1]; 21920f2268d61966230587957912491b67ad8bb91c8Yabin Cui // NOLINTNEXTLINE(whitespace/line_length) 22020f2268d61966230587957912491b67ad8bb91c8Yabin Cui // GCC: error: call to '__poll_too_small_error' declared with attribute error: poll: pollfd array smaller than fd count 22120f2268d61966230587957912491b67ad8bb91c8Yabin Cui // clang should emit a warning, but doesn't 22220f2268d61966230587957912491b67ad8bb91c8Yabin Cui poll(fds, 2, 0); 22320f2268d61966230587957912491b67ad8bb91c8Yabin Cui} 22420f2268d61966230587957912491b67ad8bb91c8Yabin Cui 22520f2268d61966230587957912491b67ad8bb91c8Yabin Cuivoid test_ppoll() { 22620f2268d61966230587957912491b67ad8bb91c8Yabin Cui pollfd fds[1]; 22720f2268d61966230587957912491b67ad8bb91c8Yabin Cui timespec timeout; 22820f2268d61966230587957912491b67ad8bb91c8Yabin Cui // NOLINTNEXTLINE(whitespace/line_length) 22920f2268d61966230587957912491b67ad8bb91c8Yabin Cui // GCC: error: call to '__ppoll_too_small_error' declared with attribute error: ppoll: pollfd array smaller than fd count 23020f2268d61966230587957912491b67ad8bb91c8Yabin Cui // clang should emit a warning, but doesn't 23120f2268d61966230587957912491b67ad8bb91c8Yabin Cui ppoll(fds, 2, &timeout, NULL); 2322fbb1b653ee46b6dee715ae7c085f094f505390dDan Albert} 233