forked from emutos/emutos
-
Notifications
You must be signed in to change notification settings - Fork 1
/
old_code.txt
28 lines (23 loc) · 1 KB
/
old_code.txt
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
old_code.c - a small Museum of Horrors
Some extensive parts of EmuTOS were written using a very old C language.
This file gives example of problems that actually occurred, and gives
the *right* way to write code.
If you fix a bug that is due to obsolete C language, please add a note in
this file to help other developers imagine what kind of nasty bug may
still exist...
- do not assign to a variable and use the old value in the same
expression. Replace
// BAD envLen = ((i = strlen (path)) + (i ? 5 : 0) + 2);
by
i = strlen (path);
envLen = i + (i ? 5 : 0) + 2;
- do not write code making assumptions about the sign of 'char':
char *prntEnvPtr;
/* look for two consecutive 0 */
// BAD while ((prntEnvPtr[i] + prntEnvPtr[i + 1]) != 0)
- do not use 0xffffffff instead of -1. 0xffffffff is the biggest
unsigned long value. Comparisons such as
long value;
// BAD if ((value & 0xFFFFFFFF) < 0)
will fail, because due to integer promotion rules the test
is done using unsigned longs.