Browse Source

Utility lib uses assert() everywhere

Thomas Buck 10 years ago
parent
commit
af0289cceb
3 changed files with 18 additions and 10 deletions
  1. 3
    0
      src/utils/math.cpp
  2. 14
    10
      src/utils/strings.cpp
  3. 1
    0
      src/utils/tga.cpp

+ 3
- 0
src/utils/math.cpp View File

9
 #include <stdlib.h>
9
 #include <stdlib.h>
10
 #include <math.h>
10
 #include <math.h>
11
 #include <float.h>
11
 #include <float.h>
12
+#include <assert.h>
12
 
13
 
13
 #include "Vector3d.h"
14
 #include "Vector3d.h"
14
 #include "Matrix.h"
15
 #include "Matrix.h"
32
         vec3_t p1, vec3_t p2,
33
         vec3_t p1, vec3_t p2,
33
         vec3_t *polygon)
34
         vec3_t *polygon)
34
 {
35
 {
36
+    assert(polygon != NULL);
37
+
35
     //  vec3_t normal, a, b;
38
     //  vec3_t normal, a, b;
36
     Vector3d a, b, normal, pA, pB;
39
     Vector3d a, b, normal, pA, pB;
37
     vec_t d, denominator, mu;
40
     vec_t d, denominator, mu;

+ 14
- 10
src/utils/strings.cpp View File

10
 #include <cstdlib>
10
 #include <cstdlib>
11
 #include <stdio.h>
11
 #include <stdio.h>
12
 #include <string.h>
12
 #include <string.h>
13
+#include <assert.h>
13
 
14
 
14
 #if defined(unix) || defined(__APPLE__)
15
 #if defined(unix) || defined(__APPLE__)
15
 #include <wordexp.h>
16
 #include <wordexp.h>
18
 #include "utils/strings.h"
19
 #include "utils/strings.h"
19
 
20
 
20
 bool stringEndsWith(const char *str, const char *suffix) {
21
 bool stringEndsWith(const char *str, const char *suffix) {
21
-    if (!str || !suffix)
22
-        return false;
22
+    assert(str != NULL);
23
+    assert(suffix != NULL);
23
 
24
 
24
     size_t lenstr = strlen(str);
25
     size_t lenstr = strlen(str);
25
     size_t lensuffix = strlen(suffix);
26
     size_t lensuffix = strlen(suffix);
36
     char *text;
37
     char *text;
37
     va_list args;
38
     va_list args;
38
 
39
 
39
-    if (!string || !string[0])
40
-        return NULL;
40
+    assert(string != NULL);
41
+    assert(string[0] != '\0');
41
 
42
 
42
     text = new char[sz];
43
     text = new char[sz];
43
 
44
 
65
     wordexp_t word;
66
     wordexp_t word;
66
     char *dir;
67
     char *dir;
67
 
68
 
68
-    if (!path || !path[0])
69
-        return NULL;
69
+    assert(path != NULL);
70
+    assert(path[0] != '\0');
70
 
71
 
71
     if (path[0] == '~') {
72
     if (path[0] == '~') {
72
 #if defined(unix) || defined(__APPLE__)
73
 #if defined(unix) || defined(__APPLE__)
127
 }
128
 }
128
 
129
 
129
 bool rc_command(const char *symbol, char *command) {
130
 bool rc_command(const char *symbol, char *command) {
130
-    if (!symbol || !symbol[0] || !command || !command[0])
131
-        return false;
131
+    assert(symbol != NULL);
132
+    assert(symbol[0] != '\0');
133
+    assert(command != NULL);
134
+    assert(command[0] != '\0');
132
 
135
 
133
     int lens = strlen(symbol);
136
     int lens = strlen(symbol);
134
 
137
 
149
 }
152
 }
150
 
153
 
151
 int rc_get_bool(const char *buffer, bool *val) {
154
 int rc_get_bool(const char *buffer, bool *val) {
152
-    if (!buffer || !buffer[0])
153
-        return -1;
155
+    assert(buffer != NULL);
156
+    assert(buffer[0] != '\0');
157
+    assert(val != NULL);
154
 
158
 
155
     if ((buffer[0] == '1') || (strncmp(buffer, "true", 4) == 0))
159
     if ((buffer[0] == '1') || (strncmp(buffer, "true", 4) == 0))
156
         *val = true;
160
         *val = true;

+ 1
- 0
src/utils/tga.cpp View File

365
     assert(width > 0);
365
     assert(width > 0);
366
     assert(height > 0);
366
     assert(height > 0);
367
     assert(s != NULL);
367
     assert(s != NULL);
368
+    assert(s[0] != '\0');
368
 
369
 
369
     va_start(args, s);
370
     va_start(args, s);
370
     vsnprintf(buffer, 1023, s, args);
371
     vsnprintf(buffer, 1023, s, args);

Loading…
Cancel
Save