Commit 72058ba
committed
[libc++] Add unsafe-buffer-usage attributes to span, vector, string and string_view
This patch is a first step towards improving the integration of
-Wunsafe-buffer-usage into the standard library. The patch basically
flags common methods of span, vector & friends as unsafe when hardening
is disabled.
This allows producing a warning diagnostic when the user explicitly
opts-into those with -Wunsafe-buffer-usage AND hardening is disabled.
For example, indexing a span with hardening disabled and the warning
enabled will now produce:
<source>:644:11: warning: function introduces unsafe buffer manipulation [-Wunsafe-buffer-usage]
644 | (void)s[3];
| ^~~~
There are certainly more places in the library that could use this
attribute and we can expand on it in the future, but this aims to
cover the most important places and provide a direction for how to
apply the same thing elsewhere.
Note that an explicit anti-goal of this patch is to set a precedent
for marking arbitrary library APIs with this attribute. There's a
large number of APIs in the library that can potentially access
pointers in unsafe way, and we should be careful to consider where
it actually makes sense to apply the attribute to make sure that these
diagnostics stay relevant (for users) and maintainable (for libc++).
Fixes #1079041 parent 3c464d2 commit 72058ba
File tree
10 files changed
+275
-44
lines changed- libcxx
- include
- __iterator
- __vector
- test
- libcxx
- containers
- sequences/vector
- views/views.span
- strings/basic.string
- std/strings/string.view
10 files changed
+275
-44
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
118 | 124 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
60 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
61 | 65 | | |
62 | 66 | | |
63 | 67 | | |
| |||
96 | 100 | | |
97 | 101 | | |
98 | 102 | | |
99 | | - | |
| 103 | + | |
| 104 | + | |
100 | 105 | | |
101 | 106 | | |
102 | 107 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
391 | 391 | | |
392 | 392 | | |
393 | 393 | | |
394 | | - | |
| 394 | + | |
| 395 | + | |
395 | 396 | | |
396 | 397 | | |
397 | 398 | | |
398 | | - | |
| 399 | + | |
| 400 | + | |
399 | 401 | | |
400 | 402 | | |
401 | 403 | | |
| |||
410 | 412 | | |
411 | 413 | | |
412 | 414 | | |
413 | | - | |
| 415 | + | |
| 416 | + | |
414 | 417 | | |
415 | 418 | | |
416 | 419 | | |
417 | | - | |
| 420 | + | |
| 421 | + | |
418 | 422 | | |
419 | 423 | | |
420 | 424 | | |
421 | | - | |
| 425 | + | |
| 426 | + | |
422 | 427 | | |
423 | 428 | | |
424 | 429 | | |
425 | | - | |
| 430 | + | |
| 431 | + | |
426 | 432 | | |
427 | 433 | | |
428 | 434 | | |
| |||
462 | 468 | | |
463 | 469 | | |
464 | 470 | | |
465 | | - | |
| 471 | + | |
466 | 472 | | |
467 | 473 | | |
468 | 474 | | |
| |||
1115 | 1121 | | |
1116 | 1122 | | |
1117 | 1123 | | |
1118 | | - | |
| 1124 | + | |
| 1125 | + | |
1119 | 1126 | | |
1120 | 1127 | | |
1121 | 1128 | | |
| |||
1126 | 1133 | | |
1127 | 1134 | | |
1128 | 1135 | | |
1129 | | - | |
| 1136 | + | |
1130 | 1137 | | |
1131 | 1138 | | |
1132 | 1139 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
323 | | - | |
| 323 | + | |
| 324 | + | |
324 | 325 | | |
325 | 326 | | |
326 | 327 | | |
327 | 328 | | |
328 | | - | |
| 329 | + | |
| 330 | + | |
329 | 331 | | |
330 | 332 | | |
331 | 333 | | |
| |||
341 | 343 | | |
342 | 344 | | |
343 | 345 | | |
344 | | - | |
| 346 | + | |
345 | 347 | | |
346 | 348 | | |
347 | 349 | | |
| |||
355 | 357 | | |
356 | 358 | | |
357 | 359 | | |
358 | | - | |
| 360 | + | |
| 361 | + | |
359 | 362 | | |
360 | 363 | | |
361 | 364 | | |
| |||
368 | 371 | | |
369 | 372 | | |
370 | 373 | | |
371 | | - | |
| 374 | + | |
372 | 375 | | |
373 | 376 | | |
374 | 377 | | |
375 | 378 | | |
376 | | - | |
| 379 | + | |
377 | 380 | | |
378 | 381 | | |
379 | 382 | | |
| |||
477 | 480 | | |
478 | 481 | | |
479 | 482 | | |
480 | | - | |
| 483 | + | |
| 484 | + | |
481 | 485 | | |
482 | 486 | | |
483 | 487 | | |
484 | 488 | | |
485 | 489 | | |
486 | | - | |
| 490 | + | |
| 491 | + | |
487 | 492 | | |
488 | 493 | | |
489 | 494 | | |
490 | 495 | | |
491 | | - | |
| 496 | + | |
| 497 | + | |
492 | 498 | | |
493 | 499 | | |
494 | 500 | | |
495 | 501 | | |
496 | | - | |
| 502 | + | |
| 503 | + | |
497 | 504 | | |
498 | 505 | | |
499 | 506 | | |
500 | 507 | | |
501 | 508 | | |
502 | | - | |
| 509 | + | |
| 510 | + | |
503 | 511 | | |
504 | 512 | | |
505 | 513 | | |
506 | 514 | | |
507 | 515 | | |
508 | 516 | | |
509 | | - | |
| 517 | + | |
510 | 518 | | |
511 | 519 | | |
512 | 520 | | |
| |||
520 | 528 | | |
521 | 529 | | |
522 | 530 | | |
523 | | - | |
| 531 | + | |
| 532 | + | |
524 | 533 | | |
525 | 534 | | |
526 | 535 | | |
| |||
533 | 542 | | |
534 | 543 | | |
535 | 544 | | |
536 | | - | |
| 545 | + | |
537 | 546 | | |
538 | 547 | | |
539 | 548 | | |
540 | 549 | | |
541 | | - | |
| 550 | + | |
542 | 551 | | |
543 | 552 | | |
544 | 553 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1340 | 1340 | | |
1341 | 1341 | | |
1342 | 1342 | | |
1343 | | - | |
| 1343 | + | |
| 1344 | + | |
1344 | 1345 | | |
1345 | 1346 | | |
1346 | 1347 | | |
1347 | 1348 | | |
1348 | 1349 | | |
1349 | 1350 | | |
1350 | 1351 | | |
1351 | | - | |
| 1352 | + | |
| 1353 | + | |
1352 | 1354 | | |
1353 | 1355 | | |
1354 | 1356 | | |
| |||
1446 | 1448 | | |
1447 | 1449 | | |
1448 | 1450 | | |
1449 | | - | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
1450 | 1455 | | |
1451 | | - | |
| 1456 | + | |
| 1457 | + | |
1452 | 1458 | | |
1453 | 1459 | | |
1454 | 1460 | | |
1455 | 1461 | | |
1456 | | - | |
| 1462 | + | |
| 1463 | + | |
1457 | 1464 | | |
1458 | 1465 | | |
1459 | 1466 | | |
1460 | 1467 | | |
1461 | | - | |
| 1468 | + | |
| 1469 | + | |
1462 | 1470 | | |
1463 | 1471 | | |
1464 | 1472 | | |
1465 | 1473 | | |
1466 | | - | |
| 1474 | + | |
| 1475 | + | |
1467 | 1476 | | |
1468 | 1477 | | |
1469 | 1478 | | |
| |||
3311 | 3320 | | |
3312 | 3321 | | |
3313 | 3322 | | |
3314 | | - | |
3315 | | - | |
3316 | | - | |
3317 | | - | |
3318 | | - | |
3319 | | - | |
3320 | 3323 | | |
3321 | 3324 | | |
3322 | 3325 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
403 | 403 | | |
404 | 404 | | |
405 | 405 | | |
406 | | - | |
| 406 | + | |
| 407 | + | |
407 | 408 | | |
408 | 409 | | |
409 | 410 | | |
410 | 411 | | |
411 | 412 | | |
412 | 413 | | |
413 | 414 | | |
414 | | - | |
| 415 | + | |
| 416 | + | |
415 | 417 | | |
416 | 418 | | |
417 | 419 | | |
418 | | - | |
| 420 | + | |
| 421 | + | |
419 | 422 | | |
420 | 423 | | |
421 | 424 | | |
422 | 425 | | |
423 | 426 | | |
424 | 427 | | |
425 | | - | |
| 428 | + | |
| 429 | + | |
426 | 430 | | |
427 | 431 | | |
428 | 432 | | |
429 | 433 | | |
430 | 434 | | |
431 | | - | |
| 435 | + | |
| 436 | + | |
432 | 437 | | |
433 | 438 | | |
434 | 439 | | |
| |||
0 commit comments