Dan Albert | 2fbb1b6 | 2014-10-08 11:21:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
George Burgess IV | c7bd90f | 2017-08-23 17:32:48 -0700 | [diff] [blame] | 17 | /* |
| 18 | * If this test fails, you can see the compiler's output by erasing a few args from the failing |
| 19 | * command. Specifically, delete everything before the path/to/the/compiler, then delete the first |
| 20 | * arg after the path/to/the/compiler. For example, given the following command: |
| 21 | * |
| 22 | * bionic/tests/file-check-cxx out/host/linux-x86/bin/FileCheck \ |
| 23 | * prebuilts/clang/host/linux-x86/clang-4053586/bin/clang++ CLANG -I bionic/tests -I ... |
| 24 | * |
Elliott Hughes | 0d1a8a5 | 2018-07-24 19:36:51 +0000 | [diff] [blame] | 25 | * If you delete everything before clang++ and delete "CLANG", then you'll end up with: |
George Burgess IV | c7bd90f | 2017-08-23 17:32:48 -0700 | [diff] [blame] | 26 | * |
| 27 | * prebuilts/clang/host/linux-x86/clang-4053586/bin/clang++ -I bionic/tests -I ... |
| 28 | * |
| 29 | * Which is the command that FileCheck executes. |
| 30 | */ |
| 31 | |
Dan Albert | 2fbb1b6 | 2014-10-08 11:21:32 -0700 | [diff] [blame] | 32 | #undef _FORTIFY_SOURCE |
| 33 | #define _FORTIFY_SOURCE 2 |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 34 | #include <fcntl.h> |
| 35 | #include <netinet/in.h> |
| 36 | #include <poll.h> |
| 37 | #include <stdarg.h> |
Dan Albert | 2fbb1b6 | 2014-10-08 11:21:32 -0700 | [diff] [blame] | 38 | #include <stdio.h> |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 39 | #include <stdlib.h> |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 40 | #include <string.h> |
| 41 | #include <sys/socket.h> |
| 42 | #include <sys/stat.h> |
| 43 | #include <time.h> |
| 44 | #include <unistd.h> |
Dan Albert | 2fbb1b6 | 2014-10-08 11:21:32 -0700 | [diff] [blame] | 45 | |
| 46 | void test_sprintf() { |
| 47 | char buf[4]; |
| 48 | |
| 49 | // NOLINTNEXTLINE(whitespace/line_length) |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 50 | // CLANG: error: call to unavailable function 'sprintf': format string will always overflow destination buffer |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 51 | sprintf(buf, "foobar"); // NOLINT(runtime/printf) |
Dan Albert | 2fbb1b6 | 2014-10-08 11:21:32 -0700 | [diff] [blame] | 52 | |
Elliott Hughes | 0d1a8a5 | 2018-07-24 19:36:51 +0000 | [diff] [blame] | 53 | // TODO: clang should emit a warning, but doesn't |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 54 | sprintf(buf, "%s", "foobar"); // NOLINT(runtime/printf) |
Dan Albert | 2fbb1b6 | 2014-10-08 11:21:32 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | void test_snprintf() { |
| 58 | char buf[4]; |
| 59 | |
| 60 | // NOLINTNEXTLINE(whitespace/line_length) |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 61 | // CLANG: error: call to unavailable function 'snprintf': format string will always overflow destination buffer |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 62 | snprintf(buf, 5, "foobar"); // NOLINT(runtime/printf) |
Dan Albert | 2fbb1b6 | 2014-10-08 11:21:32 -0700 | [diff] [blame] | 63 | |
Elliott Hughes | 0d1a8a5 | 2018-07-24 19:36:51 +0000 | [diff] [blame] | 64 | // TODO: clang should emit a warning, but doesn't |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 65 | snprintf(buf, 5, "%s", "foobar"); // NOLINT(runtime/printf) |
Dan Albert | 2fbb1b6 | 2014-10-08 11:21:32 -0700 | [diff] [blame] | 66 | |
Elliott Hughes | 0d1a8a5 | 2018-07-24 19:36:51 +0000 | [diff] [blame] | 67 | // TODO: clang should emit a warning, but doesn't |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 68 | snprintf(buf, 5, " %s ", "foobar"); // NOLINT(runtime/printf) |
Dan Albert | 2fbb1b6 | 2014-10-08 11:21:32 -0700 | [diff] [blame] | 69 | |
Elliott Hughes | 0d1a8a5 | 2018-07-24 19:36:51 +0000 | [diff] [blame] | 70 | // TODO: clang should emit a warning, but doesn't |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 71 | snprintf(buf, 5, "%d", 100000); // NOLINT(runtime/printf) |
| 72 | } |
| 73 | |
| 74 | void test_memcpy() { |
| 75 | char buf[4]; |
| 76 | |
George Burgess IV | b630046 | 2017-07-31 21:29:42 -0700 | [diff] [blame] | 77 | // CLANG: error: 'memcpy' called with size bigger than buffer |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 78 | memcpy(buf, "foobar", sizeof("foobar") + 100); |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | void test_memmove() { |
| 82 | char buf[4]; |
| 83 | |
George Burgess IV | b630046 | 2017-07-31 21:29:42 -0700 | [diff] [blame] | 84 | // CLANG: error: 'memmove' called with size bigger than buffer |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 85 | memmove(buf, "foobar", sizeof("foobar")); |
| 86 | } |
| 87 | |
| 88 | void test_memset() { |
| 89 | char buf[4]; |
| 90 | |
George Burgess IV | b630046 | 2017-07-31 21:29:42 -0700 | [diff] [blame] | 91 | // CLANG: error: 'memset' called with size bigger than buffer |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 92 | memset(buf, 0, 6); |
| 93 | } |
| 94 | |
| 95 | void test_strcpy() { |
| 96 | char buf[4]; |
| 97 | |
George Burgess IV | b630046 | 2017-07-31 21:29:42 -0700 | [diff] [blame] | 98 | // CLANG: error: 'strcpy' called with string bigger than buffer |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 99 | strcpy(buf, "foobar"); // NOLINT(runtime/printf) |
George Burgess IV | b630046 | 2017-07-31 21:29:42 -0700 | [diff] [blame] | 100 | |
George Burgess IV | b630046 | 2017-07-31 21:29:42 -0700 | [diff] [blame] | 101 | // CLANG: error: 'strcpy' called with string bigger than buffer |
| 102 | strcpy(buf, "quux"); |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | void test_stpcpy() { |
| 106 | char buf[4]; |
| 107 | |
George Burgess IV | b630046 | 2017-07-31 21:29:42 -0700 | [diff] [blame] | 108 | // CLANG: error: 'stpcpy' called with string bigger than buffer |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 109 | stpcpy(buf, "foobar"); |
George Burgess IV | b630046 | 2017-07-31 21:29:42 -0700 | [diff] [blame] | 110 | |
George Burgess IV | b630046 | 2017-07-31 21:29:42 -0700 | [diff] [blame] | 111 | // CLANG: error: 'stpcpy' called with string bigger than buffer |
| 112 | stpcpy(buf, "quux"); |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | void test_strncpy() { |
| 116 | char buf[4]; |
| 117 | |
Elliott Hughes | 0d1a8a5 | 2018-07-24 19:36:51 +0000 | [diff] [blame] | 118 | // TODO: clang should emit a warning, but doesn't |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 119 | strncpy(buf, "foobar", sizeof("foobar")); |
| 120 | } |
| 121 | |
| 122 | void test_strcat() { |
| 123 | char buf[4] = ""; |
| 124 | |
Elliott Hughes | 0d1a8a5 | 2018-07-24 19:36:51 +0000 | [diff] [blame] | 125 | // TODO: clang should emit a warning, but doesn't |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 126 | strcat(buf, "foobar"); // NOLINT(runtime/printf) |
| 127 | } |
| 128 | |
| 129 | void test_strncat() { |
| 130 | char buf[4] = ""; |
| 131 | |
Elliott Hughes | 0d1a8a5 | 2018-07-24 19:36:51 +0000 | [diff] [blame] | 132 | // TODO: clang should emit a warning, but doesn't |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 133 | strncat(buf, "foobar", sizeof("foobar")); |
| 134 | } |
| 135 | |
| 136 | void test_vsprintf(const char* fmt, ...) { |
| 137 | va_list va; |
| 138 | char buf[4]; |
| 139 | va_start(va, fmt); |
| 140 | |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 141 | // clang should emit a warning, but doesn't |
| 142 | vsprintf(buf, "foobar", va); |
| 143 | va_end(va); |
| 144 | } |
| 145 | |
| 146 | void test_vsnprintf(const char* fmt, ...) { |
| 147 | va_list va; |
| 148 | char buf[4]; |
| 149 | va_start(va, fmt); |
| 150 | |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 151 | // clang should emit a warning, but doesn't |
| 152 | vsnprintf(buf, 5, "foobar", va); // NOLINT(runtime/printf) |
| 153 | |
| 154 | va_end(va); |
| 155 | } |
| 156 | |
| 157 | void test_fgets() { |
| 158 | char buf[4]; |
| 159 | |
George Burgess IV | 23dbf82 | 2017-07-31 21:23:34 -0700 | [diff] [blame] | 160 | // CLANG: error: in call to 'fgets', size should not be negative |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 161 | fgets(buf, -1, stdin); |
| 162 | |
George Burgess IV | 23dbf82 | 2017-07-31 21:23:34 -0700 | [diff] [blame] | 163 | // CLANG: error: in call to 'fgets', size is larger than the destination buffer |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 164 | fgets(buf, 6, stdin); |
| 165 | } |
| 166 | |
| 167 | void test_recvfrom() { |
| 168 | char buf[4]; |
| 169 | sockaddr_in addr; |
| 170 | |
George Burgess IV | 54f5d83 | 2017-07-31 21:21:10 -0700 | [diff] [blame] | 171 | // CLANG: error: 'recvfrom' called with size bigger than buffer |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 172 | recvfrom(0, buf, 6, 0, reinterpret_cast<sockaddr*>(&addr), nullptr); |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 173 | } |
| 174 | |
George Burgess IV | 54f5d83 | 2017-07-31 21:21:10 -0700 | [diff] [blame] | 175 | void test_recv() { |
| 176 | char buf[4] = {0}; |
| 177 | |
George Burgess IV | 54f5d83 | 2017-07-31 21:21:10 -0700 | [diff] [blame] | 178 | // CLANG: error: 'recv' called with size bigger than buffer |
| 179 | recv(0, buf, 6, 0); |
| 180 | } |
| 181 | |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 182 | void test_umask() { |
George Burgess IV | 52dde5f | 2017-07-31 21:16:05 -0700 | [diff] [blame] | 183 | // CLANG: error: 'umask' called with invalid mode |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 184 | umask(01777); |
| 185 | } |
| 186 | |
| 187 | void test_read() { |
| 188 | char buf[4]; |
George Burgess IV | 16c1739 | 2017-07-31 21:30:47 -0700 | [diff] [blame] | 189 | // CLANG: error: in call to 'read', 'count' bytes overflows the given object |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 190 | read(0, buf, 6); |
| 191 | } |
| 192 | |
| 193 | void test_open() { |
Elliott Hughes | b115aef | 2017-08-04 09:34:19 -0700 | [diff] [blame] | 194 | // CLANG: error: 'open' called with O_CREAT or O_TMPFILE, but missing mode |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 195 | open("/dev/null", O_CREAT); |
| 196 | |
Elliott Hughes | b115aef | 2017-08-04 09:34:19 -0700 | [diff] [blame] | 197 | // CLANG: error: 'open' called with O_CREAT or O_TMPFILE, but missing mode |
| 198 | open("/dev/null", O_TMPFILE); |
| 199 | |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 200 | // CLANG: error: call to unavailable function 'open': too many arguments |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 201 | open("/dev/null", O_CREAT, 0, 0); |
George Burgess IV | 4e37d53 | 2017-08-03 17:11:35 -0700 | [diff] [blame] | 202 | |
Elliott Hughes | b115aef | 2017-08-04 09:34:19 -0700 | [diff] [blame] | 203 | // CLANG: error: call to unavailable function 'open': too many arguments |
| 204 | open("/dev/null", O_TMPFILE, 0, 0); |
| 205 | |
George Burgess IV | 4e37d53 | 2017-08-03 17:11:35 -0700 | [diff] [blame] | 206 | // CLANG: warning: 'open' has superfluous mode bits; missing O_CREAT? |
| 207 | open("/dev/null", O_RDONLY, 0644); |
| 208 | |
| 209 | // CLANG: warning: 'open' has superfluous mode bits; missing O_CREAT? |
| 210 | open("/dev/null", O_DIRECTORY, 0644); |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | void test_poll() { |
| 214 | pollfd fds[1]; |
George Burgess IV | 52dde5f | 2017-07-31 21:16:05 -0700 | [diff] [blame] | 215 | // CLANG: error: in call to 'poll', fd_count is larger than the given buffer |
Yabin Cui | 20f2268 | 2015-03-03 20:27:58 -0800 | [diff] [blame] | 216 | poll(fds, 2, 0); |
| 217 | } |
| 218 | |
| 219 | void test_ppoll() { |
| 220 | pollfd fds[1]; |
| 221 | timespec timeout; |
George Burgess IV | 52dde5f | 2017-07-31 21:16:05 -0700 | [diff] [blame] | 222 | // CLANG: error: in call to 'ppoll', fd_count is larger than the given buffer |
Elliott Hughes | b83bf14 | 2018-03-22 11:01:25 -0700 | [diff] [blame] | 223 | ppoll(fds, 2, &timeout, nullptr); |
| 224 | } |
| 225 | |
| 226 | void test_ppoll64() { |
| 227 | pollfd fds[1]; |
| 228 | timespec timeout; |
| 229 | // NOLINTNEXTLINE(whitespace/line_length) |
| 230 | // CLANG: error: in call to 'ppoll64', fd_count is larger than the given buffer |
| 231 | ppoll64(fds, 2, &timeout, nullptr); |
Dan Albert | 2fbb1b6 | 2014-10-08 11:21:32 -0700 | [diff] [blame] | 232 | } |
Daniel Micay | fed2659 | 2015-07-18 13:55:51 -0400 | [diff] [blame] | 233 | |
| 234 | void test_fread_overflow() { |
| 235 | char buf[4]; |
George Burgess IV | 23dbf82 | 2017-07-31 21:23:34 -0700 | [diff] [blame] | 236 | // CLANG: error: in call to 'fread', size * count overflows |
Daniel Micay | fed2659 | 2015-07-18 13:55:51 -0400 | [diff] [blame] | 237 | fread(buf, 2, (size_t)-1, stdin); |
| 238 | } |
| 239 | |
| 240 | void test_fread_too_big() { |
| 241 | char buf[4]; |
| 242 | // NOLINTNEXTLINE(whitespace/line_length) |
George Burgess IV | 23dbf82 | 2017-07-31 21:23:34 -0700 | [diff] [blame] | 243 | // CLANG: error: in call to 'fread', size * count is too large for the given buffer |
Daniel Micay | fed2659 | 2015-07-18 13:55:51 -0400 | [diff] [blame] | 244 | fread(buf, 1, 5, stdin); |
| 245 | } |
| 246 | |
| 247 | void test_fwrite_overflow() { |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 248 | char buf[4] = {0}; |
George Burgess IV | 23dbf82 | 2017-07-31 21:23:34 -0700 | [diff] [blame] | 249 | // CLANG: error: in call to 'fwrite', size * count overflows |
Daniel Micay | fed2659 | 2015-07-18 13:55:51 -0400 | [diff] [blame] | 250 | fwrite(buf, 2, (size_t)-1, stdout); |
| 251 | } |
| 252 | |
| 253 | void test_fwrite_too_big() { |
| 254 | char buf[4] = {0}; |
| 255 | // NOLINTNEXTLINE(whitespace/line_length) |
George Burgess IV | 23dbf82 | 2017-07-31 21:23:34 -0700 | [diff] [blame] | 256 | // CLANG: error: in call to 'fwrite', size * count is too large for the given buffer |
Daniel Micay | fed2659 | 2015-07-18 13:55:51 -0400 | [diff] [blame] | 257 | fwrite(buf, 1, 5, stdout); |
| 258 | } |
Daniel Micay | 9101b00 | 2015-05-20 15:31:26 -0400 | [diff] [blame] | 259 | |
| 260 | void test_getcwd() { |
| 261 | char buf[4]; |
George Burgess IV | 16c1739 | 2017-07-31 21:30:47 -0700 | [diff] [blame] | 262 | // CLANG: error: in call to 'getcwd', 'size' bytes overflows the given object |
Daniel Micay | 9101b00 | 2015-05-20 15:31:26 -0400 | [diff] [blame] | 263 | getcwd(buf, 5); |
| 264 | } |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 265 | |
| 266 | void test_pwrite64_size() { |
| 267 | char buf[4] = {0}; |
George Burgess IV | 16c1739 | 2017-07-31 21:30:47 -0700 | [diff] [blame] | 268 | // CLANG: error: in call to 'pwrite64', 'count' bytes overflows the given object |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 269 | pwrite64(STDOUT_FILENO, buf, 5, 0); |
| 270 | } |
| 271 | |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 272 | void test_pwrite64_too_big_malloc() { |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 273 | void *buf = calloc(atoi("5"), 1); |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 274 | // clang should emit a warning, but probably never will. |
| 275 | pwrite64(STDOUT_FILENO, buf, SIZE_MAX, 0); |
| 276 | } |
| 277 | |
| 278 | void test_pwrite64_too_big() { |
| 279 | char buf[4] = {0}; |
George Burgess IV | 16c1739 | 2017-07-31 21:30:47 -0700 | [diff] [blame] | 280 | // CLANG: error: in call to 'pwrite64', 'count' must be <= SSIZE_MAX |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 281 | pwrite64(STDOUT_FILENO, buf, SIZE_MAX, 0); |
| 282 | } |
| 283 | |
| 284 | void test_write_size() { |
| 285 | char buf[4] = {0}; |
George Burgess IV | 16c1739 | 2017-07-31 21:30:47 -0700 | [diff] [blame] | 286 | // CLANG: error: in call to 'write', 'count' bytes overflows the given object |
Daniel Micay | afdd154 | 2015-07-20 21:37:29 -0400 | [diff] [blame] | 287 | write(STDOUT_FILENO, buf, 5); |
| 288 | } |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 289 | |
| 290 | void test_memset_args_flipped() { |
| 291 | char from[4] = {0}; |
| 292 | // NOLINTNEXTLINE(whitespace/line_length) |
George Burgess IV | b630046 | 2017-07-31 21:29:42 -0700 | [diff] [blame] | 293 | // CLANG: 'memset' will set 0 bytes; maybe the arguments got flipped? |
Stephen Hines | cd659d4 | 2018-09-20 22:58:01 -0700 | [diff] [blame] | 294 | #pragma clang diagnostic push |
| 295 | #pragma clang diagnostic ignored "-Wmemset-transposed-args" |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 296 | memset(from, sizeof(from), 0); |
Stephen Hines | cd659d4 | 2018-09-20 22:58:01 -0700 | [diff] [blame] | 297 | #pragma clang diagnostic pop |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 298 | } |
Daniel Micay | 95b59c5 | 2017-02-13 17:27:59 -0800 | [diff] [blame] | 299 | |
| 300 | void test_sendto() { |
| 301 | char buf[4] = {0}; |
| 302 | sockaddr_in addr; |
| 303 | |
George Burgess IV | 54f5d83 | 2017-07-31 21:21:10 -0700 | [diff] [blame] | 304 | // CLANG: error: 'sendto' called with size bigger than buffer |
Daniel Micay | 95b59c5 | 2017-02-13 17:27:59 -0800 | [diff] [blame] | 305 | sendto(0, buf, 6, 0, reinterpret_cast<sockaddr*>(&addr), sizeof(sockaddr_in)); |
| 306 | } |
| 307 | |
| 308 | void test_send() { |
| 309 | char buf[4] = {0}; |
| 310 | |
George Burgess IV | 54f5d83 | 2017-07-31 21:21:10 -0700 | [diff] [blame] | 311 | // CLANG: error: 'send' called with size bigger than buffer |
Daniel Micay | 95b59c5 | 2017-02-13 17:27:59 -0800 | [diff] [blame] | 312 | send(0, buf, 6, 0); |
| 313 | } |
George Burgess IV | 54f5d83 | 2017-07-31 21:21:10 -0700 | [diff] [blame] | 314 | |
| 315 | void test_realpath() { |
| 316 | char buf[4] = {0}; |
| 317 | // NOLINTNEXTLINE(whitespace/line_length) |
George Burgess IV | 54f5d83 | 2017-07-31 21:21:10 -0700 | [diff] [blame] | 318 | // CLANG: error: 'realpath' output parameter must be NULL or a pointer to a buffer with >= PATH_MAX bytes |
| 319 | realpath(".", buf); |
| 320 | |
| 321 | // This is fine. |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 322 | realpath(".", nullptr); |
George Burgess IV | 54f5d83 | 2017-07-31 21:21:10 -0700 | [diff] [blame] | 323 | |
George Burgess IV | 95bd488 | 2017-08-14 14:48:55 -0700 | [diff] [blame] | 324 | char bigbuf[PATH_MAX]; |
| 325 | // CLANG: error: 'realpath': NULL path is never correct; flipped arguments? |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 326 | realpath(nullptr, bigbuf); |
George Burgess IV | 54f5d83 | 2017-07-31 21:21:10 -0700 | [diff] [blame] | 327 | } |