Replace arrays with alloca to prevent dumb warnings

snprintf now throws warning during compilation on potential buffer
overflow when using arrays.
master
Daniel Zaoui 4 years ago
parent 4203336691
commit e215368501
  1. 29
      src/bin/exactness.c

@ -108,18 +108,19 @@ _image_save(Exactness_Image *ex_img, const char *output)
static void
_file_compare(const char *orig_dir, const char *ent_name)
{
char filename1[2*EXACTNESS_PATH_MAX], filename2[2*EXACTNESS_PATH_MAX];
Exactness_Image *img1, *img2, *imgO = NULL;
snprintf(filename1, EXACTNESS_PATH_MAX, "%s/%s", orig_dir, ent_name);
snprintf(filename2, EXACTNESS_PATH_MAX, "%s/%s/%s", _dest_dir, CURRENT_SUBDIR, ent_name);
char *filename1 = alloca(strlen(orig_dir) + strlen(ent_name) + 20);
char *filename2 = alloca(strlen(_dest_dir) + strlen(ent_name) + 20);
sprintf(filename1, "%s/%s", orig_dir, ent_name);
sprintf(filename2, "%s/%s/%s", _dest_dir, CURRENT_SUBDIR, ent_name);
img1 = _image_load(filename1);
img2 = _image_load(filename2);
if (exactness_image_compare(img1, img2, &imgO))
{
char buf[2*EXACTNESS_PATH_MAX];
snprintf(buf, EXACTNESS_PATH_MAX, "%s/%s/comp_%s", _dest_dir, CURRENT_SUBDIR, ent_name);
char *buf = alloca(strlen(_dest_dir) + strlen(ent_name));
sprintf(buf, "%s/%s/comp_%s", _dest_dir, CURRENT_SUBDIR, ent_name);
_image_save(imgO, buf);
_compare_errors = eina_list_append(_compare_errors, strdup(ent_name));
}
@ -140,8 +141,8 @@ _exu_imgs_unpack(const char *exu_path, const char *dir, const char *ent_name)
if (!unit) return;
EINA_LIST_FOREACH(unit->imgs, itr, img)
{
char filename[EXACTNESS_PATH_MAX];
Eo *o = evas_object_image_add(e);
char *filename = alloca(strlen(dir) + strlen(ent_name) + 20);
snprintf(filename, EXACTNESS_PATH_MAX, "%s/%s%c%.3d.png",
dir, ent_name, SHOT_DELIMITER, n++);
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)
static void
_run_test_compare(const List_Entry *ent)
{
char path[2*EXACTNESS_PATH_MAX];
char origdir[EXACTNESS_PATH_MAX];
char *path = alloca(EXACTNESS_PATH_MAX);
char *origdir = alloca(strlen(_dest_dir) + 20);
const char *base_dir;
Eina_List *itr;
int n = 1;
@ -169,10 +170,10 @@ _run_test_compare(const List_Entry *ent)
sprintf(path, "%s/%s.exu", base_dir, ent->name);
if (ecore_file_exists(path))
{
char currentdir[EXACTNESS_PATH_MAX];
snprintf(currentdir, EXACTNESS_PATH_MAX, "%s/%s", _dest_dir, CURRENT_SUBDIR);
char *currentdir = alloca(strlen(_dest_dir) + 20);
sprintf(currentdir, "%s/%s", _dest_dir, CURRENT_SUBDIR);
_exu_imgs_unpack(path, currentdir, ent->name);
snprintf(origdir, EXACTNESS_PATH_MAX, "%s/%s/%s", _dest_dir, CURRENT_SUBDIR, ORIG_SUBDIR);
sprintf(origdir, "%s/%s/%s", _dest_dir, CURRENT_SUBDIR, ORIG_SUBDIR);
mkdir(origdir, 0744);
_exu_imgs_unpack(path, origdir, ent->name);
goto found;
@ -181,7 +182,7 @@ _run_test_compare(const List_Entry *ent)
{
sprintf(path, "%s/%s.rec", base_dir, ent->name);
if (!ecore_file_exists(path)) return;
snprintf(origdir, EXACTNESS_PATH_MAX, "%s/%s", _dest_dir, ORIG_SUBDIR);
sprintf(origdir, "%s/%s", _dest_dir, ORIG_SUBDIR);
goto found;
}
}
@ -266,8 +267,8 @@ _prefix_rm_cb(const char *name, const char *path, void *data)
const char *prefix = data;
if (_check_prefix(prefix, name))
{
char buf[EXACTNESS_PATH_MAX];
snprintf(buf, EXACTNESS_PATH_MAX, "%s/%s", path, name);
char *buf = alloca(strlen(path) + strlen(name));
sprintf(buf, "%s/%s", path, name);
if (unlink(buf))
{
printf("Failed deleting '%s/%s': ", path, name);

Loading…
Cancel
Save