arturocepeda / Cflat

Embeddable lightweight scripting language with C++ syntax
55 stars 8 forks source link

char* arrays indexing doesn't work on indexes greater then one. #19

Open mundusnine opened 7 months ago

mundusnine commented 7 months ago

When using char*[] passed from the application or from the runtime, when we try to index > 0, we get trash data in the printf call.

Basically, here is my code:

//This is in the Cflat script
char* level_names[256];
getLevelNames(level_names,&appstate->num_levels);// Populates the array with char*, I checked that data is alright before leaving the function
for(int i=0; i < appstate->num_levels;++i){
    printf("\t%s",level_names[i]);
}

Even without getLevelNames, the data we receive in the printf isn't valid i.e.:

char* level_names[256];
level_names[0] = "Test 1"; 
level_names[1] = "Test 2"; 
arturocepeda commented 7 months ago

Maybe this one is also handled with my last commit?

mundusnine commented 7 months ago

I just tested it. It sadly didn't fix it for the indexing part. I tested:

char* lev_name = level_names[i];
size_t len = strlen((const char*)lev_name);
//and
size_t len = strlen((const char*)level_names[i]);

Both return a pointer but not a valid pointer, except when we are at index 0

arturocepeda commented 6 months ago

Array accesses still needed to be adjusted to work with arrays of pointers. Please update and try again!