You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+28-6Lines changed: 28 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -57,8 +57,8 @@ and print a message a novice programmer can hopefully understand. For example:
57
57
58
58
argc = 1
59
59
a[42] = 42
60
-
a[43] = -1094795586 <-- warning appears to be uninitialized value
61
-
a[argc] = -1094795586 <-- warning appears to be uninitialized value
60
+
a[43] = <uninitialized value>
61
+
a[argc] = <uninitialized value>
62
62
63
63
# Valgrind
64
64
@@ -80,8 +80,8 @@ dcc can alternatively embed code in the binary to run valgrind instead of the bi
80
80
81
81
argc = 1
82
82
a[42] = 42
83
-
a[43] = 0
84
-
a[argc] = 0
83
+
a[43] = <uninitialized value>
84
+
a[argc] = <uninitialized value>
85
85
86
86
valgrind is slower but more comprehensive in its detection of uninitialized variables than MemorySanitizer.
87
87
@@ -150,15 +150,37 @@ extracts into it the program source and Python from the embedded tar file, and e
150
150
151
151
* starts gdb, and uses it to print current values of variables used in source lines near where the error occurred.
152
152
153
-
# Dirtying Stack Pages to Facilitate Uninitialized Variable Detection
153
+
# Facilitating Clear errors from Uninitialized Variables
154
154
155
155
Linux initializes stack pages to zero. As a consequence novice programmers writing small programs with few function calls
156
156
are likely to find zero in uninitialized local variables. This often results in apparently correct behaviour from a
157
157
invalid program with uninitialized local variables.
158
158
159
159
dcc embeds code in the binary which initializes the first few megabytes of the stack to 0xbe (see `clear-stack` in [main_wrapper.c].
160
160
161
-
When printing variable values, dcc warns the user if a variable looks to consist of 0xbe bytes, and thus is likely uninitialized.
161
+
For valgrind dcc uses its malloc-fill and --free-fill options to achieve the same result (see main_wrapper.c). AddressSanitizer & MemorySanitizer use a malloc which does this by default.
162
+
163
+
When printing variable values, dcc prints ints, doubles & pointers consisting of 0xbe bytes as "<uninitialized>".
164
+
165
+
Indirection using pointers consisting of 0xbe bytes will produced an unaligned access error from UndefinedBehaviourSanitizer, unless the pointer is to char. dcc intercepts these and explanations suitable for novice programmers (see explain_ubsan_error in [drive_gdb.py])
166
+
167
+
$ dcc dereference_uninitialized.c
168
+
$ ./a.out
169
+
tests/run_time/dereference_uninitialized_with_arrow.c:9:14: runtime error - accessing a field via an uninitialized pointer
170
+
171
+
dcc explanation: You are using a pointer which has not been initialized
172
+
A common error is using p->field without first assigning a value to p.
173
+
174
+
Execution stopped here in main() in dereference_uninitialized.c at line 9:
0 commit comments