summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Zaoui <daniel.zaoui@yahoo.com>2018-06-04 13:40:22 +0300
committerDaniel Zaoui <daniel.zaoui@yahoo.com>2018-06-04 23:37:35 +0300
commite215368501d340a43449725a8fcd883201f297db (patch)
tree200c28b86e7254222153e6c73ef7012625a020e9
parent4203336691f66a234c2670c54558a894a35d7d3a (diff)
Replace arrays with alloca to prevent dumb warnings
snprintf now throws warning during compilation on potential buffer overflow when using arrays.
-rw-r--r--src/bin/exactness.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/bin/exactness.c b/src/bin/exactness.c
index 2ef3f32..6a31336 100644
--- a/src/bin/exactness.c
+++ b/src/bin/exactness.c
@@ -108,18 +108,19 @@ _image_save(Exactness_Image *ex_img, const char *output)
108static void 108static void
109_file_compare(const char *orig_dir, const char *ent_name) 109_file_compare(const char *orig_dir, const char *ent_name)
110{ 110{
111 char filename1[2*EXACTNESS_PATH_MAX], filename2[2*EXACTNESS_PATH_MAX];
112 Exactness_Image *img1, *img2, *imgO = NULL; 111 Exactness_Image *img1, *img2, *imgO = NULL;
113 snprintf(filename1, EXACTNESS_PATH_MAX, "%s/%s", orig_dir, ent_name); 112 char *filename1 = alloca(strlen(orig_dir) + strlen(ent_name) + 20);
114 snprintf(filename2, EXACTNESS_PATH_MAX, "%s/%s/%s", _dest_dir, CURRENT_SUBDIR, ent_name); 113 char *filename2 = alloca(strlen(_dest_dir) + strlen(ent_name) + 20);
114 sprintf(filename1, "%s/%s", orig_dir, ent_name);
115 sprintf(filename2, "%s/%s/%s", _dest_dir, CURRENT_SUBDIR, ent_name);
115 116
116 img1 = _image_load(filename1); 117 img1 = _image_load(filename1);
117 img2 = _image_load(filename2); 118 img2 = _image_load(filename2);
118 119
119 if (exactness_image_compare(img1, img2, &imgO)) 120 if (exactness_image_compare(img1, img2, &imgO))
120 { 121 {
121 char buf[2*EXACTNESS_PATH_MAX]; 122 char *buf = alloca(strlen(_dest_dir) + strlen(ent_name));
122 snprintf(buf, EXACTNESS_PATH_MAX, "%s/%s/comp_%s", _dest_dir, CURRENT_SUBDIR, ent_name); 123 sprintf(buf, "%s/%s/comp_%s", _dest_dir, CURRENT_SUBDIR, ent_name);
123 _image_save(imgO, buf); 124 _image_save(imgO, buf);
124 _compare_errors = eina_list_append(_compare_errors, strdup(ent_name)); 125 _compare_errors = eina_list_append(_compare_errors, strdup(ent_name));
125 } 126 }
@@ -140,8 +141,8 @@ _exu_imgs_unpack(const char *exu_path, const char *dir, const char *ent_name)
140 if (!unit) return; 141 if (!unit) return;
141 EINA_LIST_FOREACH(unit->imgs, itr, img) 142 EINA_LIST_FOREACH(unit->imgs, itr, img)
142 { 143 {
143 char filename[EXACTNESS_PATH_MAX];
144 Eo *o = evas_object_image_add(e); 144 Eo *o = evas_object_image_add(e);
145 char *filename = alloca(strlen(dir) + strlen(ent_name) + 20);
145 snprintf(filename, EXACTNESS_PATH_MAX, "%s/%s%c%.3d.png", 146 snprintf(filename, EXACTNESS_PATH_MAX, "%s/%s%c%.3d.png",
146 dir, ent_name, SHOT_DELIMITER, n++); 147 dir, ent_name, SHOT_DELIMITER, n++);
147 evas_object_image_size_set(o, img->w, img->h); 148 evas_object_image_size_set(o, img->w, img->h);
@@ -159,8 +160,8 @@ _exu_imgs_unpack(const char *exu_path, const char *dir, const char *ent_name)
159static void 160static void
160_run_test_compare(const List_Entry *ent) 161_run_test_compare(const List_Entry *ent)
161{ 162{
162 char path[2*EXACTNESS_PATH_MAX]; 163 char *path = alloca(EXACTNESS_PATH_MAX);
163 char origdir[EXACTNESS_PATH_MAX]; 164 char *origdir = alloca(strlen(_dest_dir) + 20);
164 const char *base_dir; 165 const char *base_dir;
165 Eina_List *itr; 166 Eina_List *itr;
166 int n = 1; 167 int n = 1;
@@ -169,10 +170,10 @@ _run_test_compare(const List_Entry *ent)
169 sprintf(path, "%s/%s.exu", base_dir, ent->name); 170 sprintf(path, "%s/%s.exu", base_dir, ent->name);
170 if (ecore_file_exists(path)) 171 if (ecore_file_exists(path))
171 { 172 {
172 char currentdir[EXACTNESS_PATH_MAX]; 173 char *currentdir = alloca(strlen(_dest_dir) + 20);
173 snprintf(currentdir, EXACTNESS_PATH_MAX, "%s/%s", _dest_dir, CURRENT_SUBDIR); 174 sprintf(currentdir, "%s/%s", _dest_dir, CURRENT_SUBDIR);
174 _exu_imgs_unpack(path, currentdir, ent->name); 175 _exu_imgs_unpack(path, currentdir, ent->name);
175 snprintf(origdir, EXACTNESS_PATH_MAX, "%s/%s/%s", _dest_dir, CURRENT_SUBDIR, ORIG_SUBDIR); 176 sprintf(origdir, "%s/%s/%s", _dest_dir, CURRENT_SUBDIR, ORIG_SUBDIR);
176 mkdir(origdir, 0744); 177 mkdir(origdir, 0744);
177 _exu_imgs_unpack(path, origdir, ent->name); 178 _exu_imgs_unpack(path, origdir, ent->name);
178 goto found; 179 goto found;
@@ -181,7 +182,7 @@ _run_test_compare(const List_Entry *ent)
181 { 182 {
182 sprintf(path, "%s/%s.rec", base_dir, ent->name); 183 sprintf(path, "%s/%s.rec", base_dir, ent->name);
183 if (!ecore_file_exists(path)) return; 184 if (!ecore_file_exists(path)) return;
184 snprintf(origdir, EXACTNESS_PATH_MAX, "%s/%s", _dest_dir, ORIG_SUBDIR); 185 sprintf(origdir, "%s/%s", _dest_dir, ORIG_SUBDIR);
185 goto found; 186 goto found;
186 } 187 }
187 } 188 }
@@ -266,8 +267,8 @@ _prefix_rm_cb(const char *name, const char *path, void *data)
266 const char *prefix = data; 267 const char *prefix = data;
267 if (_check_prefix(prefix, name)) 268 if (_check_prefix(prefix, name))
268 { 269 {
269 char buf[EXACTNESS_PATH_MAX]; 270 char *buf = alloca(strlen(path) + strlen(name));
270 snprintf(buf, EXACTNESS_PATH_MAX, "%s/%s", path, name); 271 sprintf(buf, "%s/%s", path, name);
271 if (unlink(buf)) 272 if (unlink(buf))
272 { 273 {
273 printf("Failed deleting '%s/%s': ", path, name); 274 printf("Failed deleting '%s/%s': ", path, name);