fix log message reporting in my_realloc(), fix remove_symbol() if removed symbol in middle of array

This commit is contained in:
schippes 2020-08-11 02:55:24 +02:00
parent 199b408efb
commit 470f452caf
4 changed files with 10 additions and 5 deletions

View File

@ -494,6 +494,7 @@ void saveas(const char *f) /* changed name from ask_save_file to saveas 2012120
my_strncpy(current_name, rel_sym_path(res), S(current_name)); /* 20190519 */
return;
}
void ask_new_file(void)
{
char fullname[PATH_MAX]; /* overflow safe 20161125 */
@ -528,6 +529,7 @@ void ask_new_file(void)
void remove_symbol(int j)
{
int i,c;
Instdef save;
dbg(1, "remove_symbol(): removing symbol %d\n", j);
if(instdef[j].prop_ptr != NULL) {
my_free(666, &instdef[j].prop_ptr);
@ -598,9 +600,11 @@ void remove_symbol(int j)
my_free(683, &instdef[j].txtptr);
my_free(684, &instdef[j].name);
save = instdef[j];
for(i = j + 1; i < lastinstdef; i++) {
instdef[i-1] = instdef[i];
}
instdef[lastinstdef-1] = save;
lastinstdef--;
}

View File

@ -322,8 +322,8 @@ void my_realloc(int id, void *ptr,size_t size)
a = *(void **)ptr;
if(size == 0) {
free(*(void **)ptr);
dbg(3, "my_free(%d,): my_realloc_freeing %p\n",id, *(void **)ptr);
*(void **)ptr=NULL;
dbg(3, "my_free(): my_realloc_freeing %p\n",*(void **)ptr);
} else {
*(void **)ptr=realloc(*(void **)ptr,size);
if(*(void **)ptr == NULL) fprintf(errfp,"my_realloc(%d,): allocation failure\n", id);
@ -340,7 +340,7 @@ void my_free(int id, void *ptr)
dbg(3, "my_free(%d,): freeing %p\n", id, *(void **)ptr);
*(void **)ptr=NULL;
} else {
dbg(3, "my_free(%d,): trying to free NULL pointer\n", id);
dbg(3, "--> my_free(%d,): trying to free NULL pointer\n", id);
}
}

View File

@ -24,7 +24,6 @@
static struct hilight_hashentry *hilight_table[HASHSIZE];
static int nelements=0; /* 20161221 */
static int *inst_color=NULL;
static unsigned int hash(char *tok)
@ -295,6 +294,7 @@ void delete_hilight_net(void)
for(i=0;i<lastinst;i++) {
inst_ptr[i].flags &= ~4 ;
}
dbg(1, "delete_hilight_net(): clearing\n");
my_free(766, &inst_color);
hilight_color=0;
}
@ -889,6 +889,7 @@ void draw_hilight_net(int on_window)
}
}
}
dbg(1, "draw_hilight_net() : allocating inst_color %d bytes \n", lastinst*sizeof(int));
my_realloc(145, &inst_color,lastinst*sizeof(int));
for(i=0;i<lastinst;i++)
{

View File

@ -252,7 +252,7 @@ int match_symbol(const char *name) /* never returns -1, if symbol not found loa
/* dbg(1, "match_symbol(): name=%s, instdef[i].name=%s\n",name, instdef[i].name);*/
if(strcmp(name, instdef[i].name) == 0)
{
dbg(2, "match_symbol(): found matching symbol:%s\n",name);
dbg(1, "match_symbol(): found matching symbol:%s\n",name);
found=1;break;
}
}
@ -261,7 +261,7 @@ int match_symbol(const char *name) /* never returns -1, if symbol not found loa
dbg(1, "match_symbol(): matching symbol not found:%s, loading\n",name);
load_sym_def(name, NULL); /* append another symbol to the instdef[] array */
}
dbg(2, "match_symbol(): returning %d\n",i);
dbg(1, "match_symbol(): returning %d\n",i);
return i;
}