-
Notifications
You must be signed in to change notification settings - Fork 0
/
talk.tex
1035 lines (803 loc) · 18.6 KB
/
talk.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\documentclass[12pt,compress]{beamer}
\usepackage[utf8x]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{color}
\usepackage{hyperref}
\usepackage{scrextend}
\usepackage{kmath,kerkis}
\usepackage{listings}
\usetheme{Boadilla}
\setbeamertemplate{footline}
\usecolortheme{lily}
\usefonttheme{serif}
\useinnertheme{circles}
\setbeamercovered{transparent}
\beamertemplatenavigationsymbolsempty
\definecolor{darkgreen}{rgb}{0,0.5,0}
\definecolor{darkblue}{RGB}{20,20,155}
\definecolor{purple}{RGB}{51,51,178}
\hypersetup{
bookmarks=true,
unicode=true,
pdftoolbar=true,
pdfmenubar=true,
pdffitwindow=false,
pdfstartview={FitH},
pdftitle={Dark Corners of C},
pdfauthor={Michael Hartmann},
pdfcreator={vim},
pdfproducer={pdflatex},
pdfkeywords={C} {undefined behavior} {LIT} {Linux} {Infotag} {Augsburg} {LUGA},
pdfnewwindow=true,
colorlinks=true,
linkcolor=black,
citecolor=green,
filecolor=magenta,
urlcolor=darkgreen
}
\lstset{ %
commentstyle=\color{darkblue}, % comment style
keepspaces=true, % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible)
keywordstyle=\color{red}, % keyword style
basicstyle=\ttfamily\small,
language=C, % the language of the code
numbers=left, % where to put the line-numbers; possible values are (none, left, right)
numbersep=5pt, % how far the line-numbers are from the code
numberstyle=\tiny, % the style that is used for the line-numbers
}
\title{Dark Corners of C}
\institute{16. Augsburger Linux-Infotag}
\author{Michael Hartmann}
\date{22. April 2017}
\titlegraphic{\includegraphics[scale=0.2]{images/logo.png}}
\begin{document}
\begin{frame}
\titlepage
\end{frame}
\section*{Einleitung}
\frame {
\begin{center}
\only<1>
{
\includegraphics[scale=0.4]{images/gnublin.png}
}
\only<2>
{
\includegraphics[scale=0.6]{images/physik.jpg}
}
\end{center}
}
\frame {
\begin{center}
\includegraphics[scale=0.3]{images/tiobe.png}
\end{center}
}
\section{Die Sprache}
\frame {
\begin{center}
\color{purple}
\Huge Die Sprache
\end{center}
}
\subsection{Keywords}
\frame {
\frametitle{Keywords}
\texttt{{\only<2>{\color{red}}auto}
break
case
char
const
continue
default
do
double
else
enum
extern
float
for
goto
if
int
long
{\only<3>{\color{red}}register}
return
short
{\only<4>{\color{red}}signed}
sizeof
static
struct
switch
typedef
union
unsigned
void
volatile
while
}
}
\begin{frame}[fragile]
\frametitle{Kommentare}
\begin{lstlisting}
int x = 2, y = 10, z;
int *p = &x;
/* Fehler */
z = y/*p;
/* syntaktisch korrekt */
z = y/ *p;
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Kommentare}
\begin{lstlisting}
int x = 10, y;
y = x//* kommentar */2;
printf("%d\n", y);
\end{lstlisting}
\vfill
\begin{center}
C89: 5 \quad\quad C99: Fehler
\end{center}
\end{frame}
\begin{frame}
\frametitle{VLA}
Variable length arrays
\begin{itemize}
\item mandatory in C99
\item optional in C11 (?!)
\end{itemize}
\vfill
\only<2,3>
{{\it For such an object that does have a variable length array type, its
lifetime extends from the declaration of the object until execution of the
program leaves the scope of the declaration. If the scope is entered
recursively, a new instance of the object is created each time. The initial
value of the object is indeterminate.}}
\vfill
\only<3>
{
\begin{center}
{\Large Stack? \quad Heap? }
\end{center}
}
\end{frame}
\subsection{Variable length arrays}
\begin{frame}[fragile]
\frametitle{VLA}
\begin{lstlisting}
double sum(size_t nmax) {
double sum = 0, buf[nmax];
for(size_t i = 0; i < nmax; i++)
buf[i] = 1./(1+i);
for(size_t i = 0; i < nmax; i++)
sum += buf[i];
return sum;
}
sum(100); // 5.18738...
sum(10000000); // Segmentation Fault
\end{lstlisting}
\end{frame}
\section{Macros}
\frame {
\begin{center}
\color{purple}
\Huge Macros
\end{center}
}
\begin{frame}[fragile]
\frametitle{Macros}
\begin{lstlisting}
#define SQUARE(x) x*x
SQUARE(2+1);
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Macros}
\begin{lstlisting}
#define SQUARE(x) x*x
SQUARE(2+1); // 2+1*2+1 = 5
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Macros}
\begin{lstlisting}
#define SQUARE(x) (x)*(x)
SQUARE(2+1);
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Macros}
\begin{lstlisting}
#define SQUARE(x) (x)*(x)
SQUARE(2+1); // (2+1)*(2+1) = 9
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Macros}
\begin{lstlisting}
#define SQUARE(x) (x)*(x)
SQUARE(2+1); // (2+1)*(2+1) = 9
1./SQUARE(2+1); // 1/.(2+1)*(2+1) = 1.
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Macros}
\begin{lstlisting}
#define SQUARE(x) ((x)*(x))
1./SQUARE(2+1); // 1/.(2+1)*(2+1) = 1.
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Macros}
\begin{lstlisting}
#define SQUARE(x) ((x)*(x))
1./SQUARE(2+1); // 1/.(2+1)*(2+1) = 1.
SQUARE(3000000000); // -494665728
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Macros}
\begin{lstlisting}
#define SQUARE(x) ((x)*(x))
1./SQUARE(2+1); // 1/.(2+1)*(2+1) = 1.
SQUARE(3000000000); // -494665728
SQUARE(3000000000.); // 9e18
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Macros}
\begin{lstlisting}
#define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
min(a,b++);
min(x+y,foo(z));
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Macros}
\begin{lstlisting}
#define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
min(a,min(b,min(c,d)));
/* becomes */
((a) < (((b) < (((c) < (d) ? (c) : (d))) ?
(b) : (((c) < (d) ? (c) : (d))))) ?
(a) : (((b) < (((c) < (d) ?
(c) : (d))) ? (b) : (((c) < (d) ?
(c) : (d))))));
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Macros}
\begin{lstlisting}
#define assert(e) \
if(!e) panic(__FILE__, __LINE__)
int x = 0, y = 1;
assert(x > y);
/* becomes */
if(!0 > 1) /* 1 > 1 */
panic(...);
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Macros}
\begin{lstlisting}
#define assert(e) \
if(!(e)) panic(__FILE__, __LINE__)
if(x > 0 && y > 0)
assert(x > y);
else
assert(y > x);
/* becomes */
if(x > 0 && y > 0)
if(!(x > y))
panic(...);
else
if(!(y > x))
panic(...);
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Macros}
\begin{lstlisting}
#define assert(e) \
{ if(!(e)) panic(__FILE__, __LINE__); }
if(x > 0 && y > 0)
assert(x > y);
else
assert(y > x);
/* becomes */
if(x > 0 && y > 0)
{ if(!(x > y)) panic(...); };
else
{ if(!(y > x)) panic(...); };
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Macros}
\begin{lstlisting}
/* correct */
#define assert(e) \
(void)((e)||panic(__FILE__, __LINE__))
/* should also work */
#define assert(e) \
do { if(!(e)) panic(__FILE__, __LINE__); } \
while(0)
\end{lstlisting}
\end{frame}
\section{Standardbibliothek}
\frame {
\begin{center}
\color{purple}
\Huge Standardbibliothek
\end{center}
}
\begin{frame}[fragile]
\frametitle{\texttt{gets}}
\begin{lstlisting}
char *gets(char *s);
\end{lstlisting}
\vfill
Never use \texttt{gets()}. Because it is impossible to tell without knowing
the data in advance how many characters \texttt{gets()} will read, and because
\texttt{gets()} will continue to store characters past the end of the buffer,
it is extremely dangerous to use. It has been used to break computer security.
\end{frame}
\begin{frame}[fragile]
\frametitle{\texttt{realloc}}
\begin{lstlisting}
char *buf = (char *)malloc(elems*sizeof(char));
if(buf == NULL)
...
...
buf = realloc(buf, newelems*sizeof(char));
if(buf == NULL)
/* Memory leak */
...
\end{lstlisting}
\end{frame}
\frame {
\frametitle{\texttt{lgamma}}
\only<1>
{
The \texttt{lgamma()} function returns the natural logarithm of the absolute
value of the Gamma function. The sign of the Gamma function is returned in the
external integer \texttt{signgam} declared in \texttt{<math.h>}. [$\dots$]
}
\only<2->
{
Since using a constant location \texttt{signgam} is not thread-safe, the functions
\texttt{lgamma\_r()}, \texttt{lgammaf\_r()}, and \texttt{lgammal\_r()} have been
introduced; they return the sign via the argument \texttt{signp}.
}
\only<3>
{
\vfill
\texttt{lgamma\_r(), lgammaf\_r(), lgammal\_r()}: \\
\quad\quad\quad \texttt{\_BSD\_SOURCE || \_SVID\_SOURCE}
}
}
\begin{frame}[fragile]
\frametitle{\texttt{errno}}
\begin{lstlisting}
library_function();
if(errno)
/* Fehlerbehandlung */
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{\texttt{errno}}
\begin{lstlisting}
errno = 0;
library_function();
if(errno)
/* Fehlerbehandlung */
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{\texttt{errno}}
\begin{lstlisting}
ret = library_function();
if(error_condition)
/* inspect errno */
\end{lstlisting}
\end{frame}
\section{Undefined behavior}
\frame {
\begin{center}
\color{purple}
\Huge Undefined behavior
\end{center}
}
\begin{frame}[fragile]
\frametitle{Undefined behavior}
\begin{lstlisting}
int buffer[] = { 1,2,3 };
int x = buffer[3];
printf("%d\n", x);
\end{lstlisting}
\vfill
mögliche Ausgabe
\begin{itemize}
\item 0
\item 42
\item -1
\item \texttt{Überschreibe Festplatte...}
\end{itemize}
\end{frame}
\frame {
\frametitle{Was ist undefiniert?}
\begin{itemize}
\item lesen uninitialisierter Variablen
\item Dereferenzieren von wilden Pointern, Out of Bounds Array Accesses
\item Dereferenzieren des \texttt{NULL} Pointers
\item Casting: \texttt{int *} nach \texttt{float *} casten und Pointer dereferenzieren
\item Integer Division durch 0
\item {\it An unmatched ‘ or ” character is encountered on a logical source line during tokenization.}
\item ...
\end{itemize}
}
\begin{frame}[fragile]
\frametitle{Kürzeste Funktion mit undefinierten Verhalten}
\begin{lstlisting}
int f(int x) { return -x; }
int main(void)
{
printf("f(%d)=%d\n", INT_MIN, f(INT_MIN));
return 0;
}
\end{lstlisting}
\vfill
auf meinem Rechner:
\texttt{f(-2147483648)=-2147483648}
\end{frame}
\frame {
\frametitle{Zweierkomplement}
\begin{center}
\begin{tabular}{c|c}
Bits & Wert \\
\hline
011 & 3 \\
010 & 2 \\
001 & 1 \\
000 & 0 \\
111 & −1 \\
110 & −2 \\
101 & −3 \\
100 & -4
\end{tabular}
\end{center}
\begin{center}
{\color{red}Aber:} Der Compiler kann machen, was er will!
\end{center}
}
\begin{frame}[fragile]
\frametitle{Vorteile}
\begin{itemize}
\item uninitialisierte Variablen: \texttt{memset} für Arrays teuer...
\item Signed integer overflows:
\begin{lstlisting}
int i;
i+1 > i; /* true */
i*2/2; /* i */
/* Schleife wird N+1 mal ausgefuehrt */
for(i = 0; i <= N; ++i) {
...
}
\end{lstlisting}
\item Out of Bounds Array Access: Checks zur Laufzeit teuer, würde Binärkompatibilität mit alten Programmen brechen
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Undefiniertes Verhalten und Optimierungen}
\begin{lstlisting}
void f(int *P) {
int dead = *P;
if (P == NULL)
return;
*P = 4;
}
\end{lstlisting}
\vfill
Zwei Optimierungen:
\begin{itemize}
\item Dead Code Elimination
\item Redundant Null Check Elimination:
\end{itemize}
\vfill
Verhalten hängt von der Reihenfolge der Optimierungen ab!
\end{frame}
\begin{frame}[fragile]
\frametitle{Undefiniertes Verhalten und Optimierungen}
Dead Code Elimination:
\vfill
\begin{lstlisting}
void f(int *P) {
int dead = *P; /* dead code */
if (P == NULL)
return;
*P = 4;
}
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Undefiniertes Verhalten und Optimierungen}
Redundant Null Check Elimination:
\vfill
\begin{lstlisting}
void f(int *P) {
if (P == NULL) /* Check nicht redundant */
return;
*P = 4;
}
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Undefiniertes Verhalten und Optimierungen}
Code mit zuerst DCE und danach RNCE:
\vfill
\begin{lstlisting}
void f(int *P) {
if (P == NULL)
return;
*P = 4;
}
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Undefiniertes Verhalten und Optimierungen}
\begin{center}
Und jetzt anders herum!
\end{center}
\end{frame}
\begin{frame}[fragile]
\frametitle{Undefiniertes Verhalten und Optimierungen}
Redundant Null Check Elimination:
\vfill
\begin{lstlisting}
void f(int *P) {
int dead = *P;
if (P == NULL) /* P darf nicht NULL sein */
return;
*P = 4;
}
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Undefiniertes Verhalten und Optimierungen}
Dead code elimination:
\vfill
\begin{lstlisting}
void f(int *P) {
int dead = *P; /* dead code */
*P = 4;
}
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Undefiniertes Verhalten und Optimierungen}
Code mit zuerst RNCE und danach DCE:
\vfill
\begin{lstlisting}
void f(int *P) {
*P = 4;
}
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Undefiniertes Verhalten und Security}
\begin{lstlisting}
void process_something(int size) {
/* check for integer overflow */
if (size > size+1)
abort();
...
/* alles ok hier */
char *string = malloc(size+1);
read(fd, string, size);
string[size] = 0;
do_something(string);
free(string);
}
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Undefiniertes Verhalten und Security}
Signed integer Overflows sind undefiniert...
\vfill
Nach Optimieren sieht der Code vermutlich so aus:
\vfill
\begin{lstlisting}
void process_something(int size) {
...
/* alles ok hier */
char *string = malloc(size+1);
read(fd, string, size);
string[size] = 0;
do_something(string);
free(string);
}
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Real-world Beispiel}
\begin{lstlisting}
void __devexit agnx_pci_remove (struct pci_dev *pdev)
{
struct ieee80211_hw *dev = pci_get_drvdata(pdev);
struct agnx_priv *priv = dev->priv;
if (!dev)
return;
...
}
\end{lstlisting}
\end{frame}
\frame {
\frametitle{gcc}
\texttt{-fdelete-null-pointer-checks}: \\
\begin{addmargin}[1em]{2em}
Assume that programs cannot safely dereference null pointers, and that no code or data element resides there. This enables simple constant folding optimizations at all optimization levels. In
addition, other optimization passes in GCC use this flag to control global dataflow analyses that eliminate useless checks for null pointers; these assume that if a pointer is checked after it
has already been dereferenced, it cannot be null.
\vfill
Note however that in some environments this assumption is not true. Use
\texttt{-fno-delete-null-pointer-checks} to disable this optimization for programs that
depend on that behavior.
\end{addmargin}
}
\begin{frame}[fragile]
\frametitle{Undefiniertes Verhalten und Debugging...}
\begin{lstlisting}
void f(bool b) {
if(b)
printf("true\n");
else
printf("false\n");
}
int main(int argc, char *argv[]) {
bool *p = (bool *)malloc(sizeof(bool));
f(*p);
f(!*p);
return 0;
}
\end{lstlisting}
\end{frame}
\frame {
\frametitle{Undefiniertes Verhalten und Debugging...}
\only<1> {
\texttt{\$ gcc -Wall -Wextra -O2 truefalse.c \\
\$ ./a.out \\
false \\
true}
}
\only<2> {
\texttt{\$ clang -Wall -Wextra -Oz truefalse.c \\
\$ ./a.out \\
false \\
false
}
}
}
\section{Helfer}
\frame {
\begin{center}
\color{purple}
\Huge Helfer
\end{center}
}
\frame {
\frametitle{Helfer}
\begin{itemize}
\item Compiler Warnungen: \texttt{-Wall -Wextra}
\item Clang Static Analyzer
\item Clang's \texttt{-fsanitize} Option
\item valgrind
\item gcc integer overflow builtins:
\texttt{\_\_builtin\_add\_overflow},
\texttt{\_\_builtin\_mul\_overflow}, ...
\end{itemize}
}
\frame {
\frametitle{Clang Static Analyzer}
\begin{center}
\includegraphics[scale=0.5]{images/clang-static.png}
\end{center}
}
\frame {
\frametitle{valgrind}
{ \small
\texttt{\$ valgrind ./a.out \\
\ \\
==27502== Conditional jump or move depends on uninitialised value(s) \\
==27502== at 0x400573: f (in a.out) \\
==27502== by 0x400467: main (in a.out) \\
==27502== \\
false \\
...
}
}
}
\frame {
\frametitle{Clang's \texttt{-fsanitize} Option}
{ \small
\texttt{\$ clang -fsanitize=undefined,memory truefalse.c \\
\$ ./a.out \\
==27607== WARNING: MemorySanitizer: use-of-uninitialized-value \\
\quad\quad\#0 0x7f53cadbd873 (a.out+0x94873) \\
\quad\quad\#1 0x7f53c9c3cb44 (libc.so.6+0x21b44) \\
\quad\quad\#2 0x7f53cadbd38c (a.out+0x9438c) \\
\ \\
SUMMARY: MemorySanitizer: use-of-uninitialized-value ??:0 ?? \\
Exiting
}
}
}
\frame {
\begin{center}
\color{purple}
\Huge Vielen Dank für die Aufmerksamkeit!
\end{center}
\vfill
{
Credits and links:
\begin{itemize}
\item \hyperlink{http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html}{What Every C Programmer Should Know About Undefined (LLVM)}
\item \hyperlink{http://blog.regehr.org/archives/213}{A Guide to Undefined Behavior in C and C++ (Embedded in Academia)}
\item \hyperlink{https://markshroyer.com/2012/06/c-both-true-and-false/}{Both true and false (mark shroyer, dot com)}
\item \hyperlink{http://tinyurl.com/mrv44kk}{Some dark corners of C (Rob Kendrick)}
\item \hyperlink{https://clang-analyzer.llvm.org/}{Clang Static Analyzer}
\end{itemize}
}
}
\frame {
\begin{center}
\color{purple}
\Huge Bonus Folien
\end{center}
}
\begin{frame}[fragile]
\frametitle{Find a bug}
\begin{lstlisting}
int div(int a, int b)
{
assert(b != 0);
return a / b;
}
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Find a bug}
\begin{lstlisting}
const char *str = "Hallo Welt";
size_t length = strlen(str);
for(size_t i = length - 1; i >= 0; i--)
putchar(str[i]);
\end{lstlisting}