Skip to content

Commit

Permalink
Fix for non-portable behavior of realloc.
Browse files Browse the repository at this point in the history
  • Loading branch information
redcode committed Dec 24, 2024
1 parent 463fe59 commit e259451
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions sources/step-test-Z80.c
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ int main(int argc, char **argv)
do {
if ((json = realloc(json, (buffer_size += INPUT_BLOCK_SIZE) + 1)) == Z_NULL)
{
error = "cannot allocate memory";
error = "cannot allocate memory 1";
break;
}

Expand Down Expand Up @@ -744,7 +744,7 @@ int main(int argc, char **argv)
error = "cannot determine file size";

else if ((json = malloc(file_size + 1)) == Z_NULL)
error = "cannot allocate memory";
error = "cannot allocate memory 2";

else if (fread(json, file_size, 1, file) != 1)
error = "I/O error";
Expand Down Expand Up @@ -782,8 +782,8 @@ int main(int argc, char **argv)
else {
cJSON *test;

if ( (cycles = realloc(cycles, cycles_size * sizeof(Cycle))) == Z_NULL ||
(ports = realloc(ports, ports_size * sizeof(Port ))) == Z_NULL
if ( ((cycles = realloc(cycles, cycles_size * sizeof(Cycle))) == Z_NULL && cycles_size) ||
((ports = realloc(ports, ports_size * sizeof(Port ))) == Z_NULL && ports_size )
)
{
cannot_allocate_memory:
Expand Down Expand Up @@ -850,7 +850,7 @@ int main(int argc, char **argv)
/* Run test */
z80_run(&cpu, expected_cycle_count);

if (cycles == Z_NULL || ports == Z_NULL)
if ((cycles_size && cycles == Z_NULL) || (ports_size && ports == Z_NULL))
goto cannot_allocate_memory;

test_failed = array_failed = Z_FALSE;
Expand Down

0 comments on commit e259451

Please sign in to comment.