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

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

@@ -10,6 +10,7 @@
10 10
 #include <cstdlib>
11 11
 #include <stdio.h>
12 12
 #include <string.h>
13
+#include <assert.h>
13 14
 
14 15
 #if defined(unix) || defined(__APPLE__)
15 16
 #include <wordexp.h>
@@ -18,8 +19,8 @@
18 19
 #include "utils/strings.h"
19 20
 
20 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 25
     size_t lenstr = strlen(str);
25 26
     size_t lensuffix = strlen(suffix);
@@ -36,8 +37,8 @@ char *bufferString(const char *string, ...) {
36 37
     char *text;
37 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 43
     text = new char[sz];
43 44
 
@@ -65,8 +66,8 @@ char *fullPath(const char *path, char end) {
65 66
     wordexp_t word;
66 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 72
     if (path[0] == '~') {
72 73
 #if defined(unix) || defined(__APPLE__)
@@ -127,8 +128,10 @@ char *fullPath(const char *path, char end) {
127 128
 }
128 129
 
129 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 136
     int lens = strlen(symbol);
134 137
 
@@ -149,8 +152,9 @@ bool rc_command(const char *symbol, char *command) {
149 152
 }
150 153
 
151 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 159
     if ((buffer[0] == '1') || (strncmp(buffer, "true", 4) == 0))
156 160
         *val = true;

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

@@ -365,6 +365,7 @@ int tgaSaveFilename(unsigned char *image, unsigned int width, unsigned int heigh
365 365
     assert(width > 0);
366 366
     assert(height > 0);
367 367
     assert(s != NULL);
368
+    assert(s[0] != '\0');
368 369
 
369 370
     va_start(args, s);
370 371
     vsnprintf(buffer, 1023, s, args);

Loading…
Cancel
Save