Commit 73bc74a
committed
Avoid footgun.
Factor temporary std::string instance to separate variable
as this prolongs its lifetime long enough for result of
.c_str to survive. Otherwise printf could obtain pointer
to already destructed string.
For more information consult GotW #88 at [1].
[1] https://herbsutter.com/2008/01/01/gotw-88-a-candidate-for-the-most-important-const/1 parent b2daa48 commit 73bc74a
1 file changed
Lines changed: 6 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
36 | | - | |
| 37 | + | |
| 38 | + | |
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
43 | | - | |
| 45 | + | |
| 46 | + | |
44 | 47 | | |
45 | 48 | | |
46 | 49 | | |
| |||
0 commit comments