]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Clean up code
authorAlan T. DeKok <aland@freeradius.org>
Thu, 14 Mar 2013 20:50:33 +0000 (16:50 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 14 Mar 2013 20:50:33 +0000 (16:50 -0400)
Use uint8_t rather than char && casts.
Don't assign to variables inside of an "if" condition.  It's
bad form.

src/modules/rlm_sql/drivers/rlm_sql_sqlite/rlm_sql_sqlite.c

index bdb5f98486b8f67d2a6f5203b0dcdac214631bc3..1e242293ae56448f38970684d6e1a6c5a29775ca 100644 (file)
@@ -147,11 +147,10 @@ static int sql_loadfile(sqlite3 *db, const char *filename)
                return -1;       
        }
        
-       MEM(buff = talloc_array(NULL, char, finfo.st_size + 1));
+       MEM(buff = talloc_array(NULL, uint8_t, finfo.st_size + 1));
        len = fread(buff, sizeof(char), finfo.st_size + 1, f);
        if (len > finfo.st_size) {
                talloc_free(buff);
-       
                goto too_big;
        } 
        
@@ -175,25 +174,25 @@ static int sql_loadfile(sqlite3 *db, const char *filename)
        }
        
        buff[len] = '\0';
-       
        fclose(f);
 
        /*
         *      Check input encoding is UTF8 compliant
         */
-       p = buff;
-       while(((*p == '\xa') && (cl = 1)) ||
-             ((*p == '\xd') && (cl = 1)) ||
-             (cl = fr_utf8_char((uint8_t *) p))) {
-               p += cl;
+       for (p = buff; *p != '\0'; p += cl) {
+               if (*p < ' ') {
+                       if ((*p != 0x0a) && (*p != 0x0d)) break;
+                       cl = 1;
+               } else {
+                       cl = fr_utf8_char(p);
+                       if (!cl) break;
+               }
        }
        
-       if (p != (buff + len)) {
+       if (*p) {
                radlog(L_ERR, "rlm_sql_sqlite: Bootstrap file contains "
-                      "none UTF8 char at offset %zu", p - buff);
-                      
+                      "non-UTF8 char at offset %zu", p - buff);
                talloc_free(buff);
-               
                return -1;
        }