Skip to content

Commit ddcb14c

Browse files
committed
minor updates to documentation
1 parent 175a2ca commit ddcb14c

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

README.md

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ and print a message a novice programmer can hopefully understand. For example:
5757

5858
argc = 1
5959
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>
6262

6363
# Valgrind
6464

@@ -80,8 +80,8 @@ dcc can alternatively embed code in the binary to run valgrind instead of the bi
8080

8181
argc = 1
8282
a[42] = 42
83-
a[43] = 0
84-
a[argc] = 0
83+
a[43] = <uninitialized value>
84+
a[argc] = <uninitialized value>
8585

8686
valgrind is slower but more comprehensive in its detection of uninitialized variables than MemorySanitizer.
8787

@@ -150,15 +150,37 @@ extracts into it the program source and Python from the embedded tar file, and e
150150

151151
* starts gdb, and uses it to print current values of variables used in source lines near where the error occurred.
152152

153-
# Dirtying Stack Pages to Facilitate Uninitialized Variable Detection
153+
# Facilitating Clear errors from Uninitialized Variables
154154

155155
Linux initializes stack pages to zero. As a consequence novice programmers writing small programs with few function calls
156156
are likely to find zero in uninitialized local variables. This often results in apparently correct behaviour from a
157157
invalid program with uninitialized local variables.
158158

159159
dcc embeds code in the binary which initializes the first few megabytes of the stack to 0xbe (see `clear-stack` in [main_wrapper.c].
160160

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:
175+
176+
int main(void) {
177+
struct list_node *a = malloc(sizeof *a);
178+
--> a->next->data = 42;
179+
}
180+
181+
Values when execution stopped:
182+
183+
a->next = <uninitialized value>
162184

163185
# Build Instructions
164186

0 commit comments

Comments
 (0)