subsequenct sceIoRead calls crashing

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
sexdwarf
Posts: 34
Joined: Thu Jul 14, 2005 12:07 am

subsequenct sceIoRead calls crashing

Post by sexdwarf »

i am having an issue reading with sceIoRead... any initial call works, however any subsequent calls crash the PSP, and i've concluded that it's not related to the file (switching the order works the same way) etc...

here is the code:

Code: Select all

WaveInfo *wavLoad (char *filename)
{
    unsigned int filelen;
    unsigned long datalength;
    int data_offset;
    int id;
    int size;
    int fd;
    unsigned char   *wavfile;
    char            path_name[256];
    WaveInfo *wi;

    SceIoStat stat;
    sprintf(path_name,"%s%s", g_boot_path, filename);

    fd = sceIoOpen(path_name, PSP_O_RDONLY, 0777);

    if &#40;fd<0&#41;
    &#123;
        printf&#40;"Failed loading&#58; %s",path_name&#41;;
    &#125;
    else
    &#123;
// ---- Definatly gets here...
printf&#40;"1-GOT HERE\n"&#41;;
        sceIoGetstat&#40;path_name,&stat&#41;;
printf&#40;"2-GOT HERE\n"&#41;;
        wi = malloc&#40;stat.st_size + sizeof&#40;WaveInfo&#41;&#41;;
printf&#40;"3-GOT HERE\n"&#41;;

        wavfile = &#40;char*&#41;&#40;wi + sizeof&#40;WaveInfo&#41;&#41;;
printf&#40;"4-GOT HERE\n"&#41;;
        filelen = sceIoRead&#40;fd, wavfile, stat.st_size&#41;;
printf&#40;"5-GOT HERE\n"&#41;;
        sceIoClose&#40;fd&#41;;
printf&#40;"6-GOT HERE\n"&#41;;

// dies before here
it always dies right after "4-GOT HERE" when being called a second time...anyone have any ideas?
...isn't it nice, sugar and spice...
...luring disco dollies to a life of vice...
remleduff
Posts: 11
Joined: Sun Jul 24, 2005 3:29 am

Re: subsequenct sceIoRead calls crashing

Post by remleduff »

sexdwarf wrote:

Code: Select all

        wavfile = &#40;char*&#41;&#40;wi + sizeof&#40;WaveInfo&#41;&#41;;
sizeof(*wi) is presumably != sizeof(char) so you're overrunning the end of your memory.

Try:
wavfile = (char*)wi + sizeof(WaveInfo);

I would actually recommend you just allocate the two pointers in two separate mallocs.
Post Reply