Browse code

Properly upconvert from char to int

Shawn Webb authored on 2014/05/30 04:52:43
Showing 3 changed files
... ...
@@ -157,7 +157,7 @@ typedef struct cli_ctx_tag {
157 157
 typedef struct cli_flagged_sample {
158 158
     char **virus_name;
159 159
     char md5[16];
160
-    size_t size; /* A size of zero means size is unavailable (why would this ever happen?) */
160
+    uint32_t size; /* A size of zero means size is unavailable (why would this ever happen?) */
161 161
     uint32_t hits;
162 162
     stats_section_t *sections;
163 163
 
... ...
@@ -258,7 +258,7 @@ void clamav_stats_add_sample(const char *virname, const unsigned char *md5, size
258 258
         sample->virus_name[i+1] = NULL;
259 259
 
260 260
         memcpy(sample->md5, md5, sizeof(sample->md5));
261
-        sample->size = size;
261
+        sample->size = (uint32_t)size;
262 262
         intel->nsamples++;
263 263
 
264 264
         if (sections && sections->nsections && !(sample->sections)) {
... ...
@@ -48,13 +48,16 @@ char *hex_encode(char *buf, char *data, size_t len)
48 48
 {
49 49
     size_t i;
50 50
     char *p;
51
+    int t;
51 52
 
52 53
     p = (buf != NULL) ? buf : calloc(1, (len*2)+1);
53 54
     if (!(p))
54 55
         return NULL;
55 56
 
56
-    for (i=0; i<len; i++)
57
-        sprintf(p+(i*2), "%02x", (int)data[i]);
57
+    for (i=0; i<len; i++) {
58
+        t = data[i] & 0xff;
59
+        sprintf(p+(i*2), "%02x", t);
60
+    }
58 61
 
59 62
     return p;
60 63
 }
... ...
@@ -132,7 +135,7 @@ char *export_stats_to_json(struct cl_engine *engine, cli_intel_t *intel)
132 132
         snprintf(buf+curused, bufsz-curused, "\t\t\t\"hits\": %s,\n", md5);
133 133
         curused += strlen(buf+curused);
134 134
 
135
-        snprintf(md5, sizeof(md5), "%zu", sample->size);
135
+        snprintf(md5, sizeof(md5), "%u", sample->size);
136 136
 
137 137
         buf = ensure_bufsize(buf, &bufsz, curused, strlen(md5) + 20);
138 138
         if (!(buf))
... ...
@@ -176,7 +179,7 @@ char *export_stats_to_json(struct cl_engine *engine, cli_intel_t *intel)
176 176
                 if (!(buf))
177 177
                     return NULL;
178 178
 
179
-                snprintf(buf+curused, bufsz-curused, "\t\t\t\t\t\"size\": %zu\n", sample->sections->sections[i].len);
179
+                snprintf(buf+curused, bufsz-curused, "\t\t\t\t\t\"size\": %u\n", sample->sections->sections[i].len);
180 180
                 curused += strlen(buf+curused);
181 181
 
182 182
                 buf = ensure_bufsize(buf, &bufsz, curused, 30);