SIGSEGV error in using a pointer

Asked

Viewed 56 times

0

I have the following problem: I am creating a pointer and allocating memory in it, passing its reference to function, but when I read it in the function happens the error reported in the title.

Function:

void FileLer(char *texto, char *file)
{
    //
    //  Retorno
    //
    int ret = 99;

    //
    //  Handle
    //
    UINT FileHandleLer = 0;

    //
    //  Tamanho do Buffer
    //
    UINT BufferLenLer = 0;

    //
    //  Pega o tamanho do arquivo
    //
    GEDI_FS_FileSizeGet(file, 1, &BufferLenLer);

    if(BufferLenLer > 0)
    {

        GEDI_LCD_DrawString(5,  FONT_HEIGHT*5, FONT_WIDTH*0.7, FONT_HEIGHT*0.7, "File Ok! %d", BufferLenLer);

        GEDI_CLOCK_Delay(1000);

    }
    else
    {

        GEDI_LCD_DrawString(5, FONT_HEIGHT*5, FONT_WIDTH*0.7, FONT_HEIGHT*0.7, "Erro! ");

        GEDI_CLOCK_Delay(1000);

        //
        //  Para a funcao
        //
        return;

    }

    //
    //  Abre um arquivo
    //
    ret = GEDI_FS_FileOpen(file, 3, GEDI_FS_STORAGE_PUBLIC, &FileHandleLer);

    ret = GEDI_FS_FileRead(FileHandleLer, &texto, &BufferLenLer);

    int b = strlen(texto);     <<<<<< -- Linha com o erro 

    //
    //  Fecha o socket
    //
    ret = GEDI_FS_FileClose(FileHandleLer);

    //
    //  Zera Variaveis
    //
    ret                 =   0;
    FileHandleLer       =   0;
    BufferLenLer        =   0;
}

Calling for:

char *buffer            =   (char *)malloc(1024*(sizeof(char)));

//
//  Le o arquivo IP
//
FileLer(buffer, "configIP.txt");
  • 2

    Young woman organized in this code there, to facilitate the reading of it.

  • In the GEDI_LCD_DrawString(5, FONT_HEIGHT*5, FONT_WIDTH*0.7, FONT_HEIGHT*0.7, "Erro! %d"); - That one %d will not work because a parameter is missing.

  • What is the purpose of int b = strlen(texto); if the variable b will not be used for anything after and the strlen should not produce side effects?

  • What documentation of GEDI_FS_FileRead()?

  • Victor Stafusa, I’ve noticed that, but he’s not falling for Isis, that’s not the problem, but thank you

  • strange that when I do the same function using only local variables it works, but when I try the same by passing parameter it happens this

  • Victor Stafusa, just to identify the problem.

  • &texto and texto are different things. The first has kind char **, the second has kind char *. The first points to a local variable to the function FileLer(), the second points to an external string.

  • I googled GEDI_FS_FileSizeGet, GEDI_FS_FileOpen, GEDI_FS_FileRead, GEDI_FS_FileClose, GEDI_LCD_DrawString, GEDI_CLOCK_Delay and GEDI_FS_STORAGE_PUBLIC - Many of these google has never heard of. The ones he knows point to a question you asked here in July and to websites that copied the content of your other question to republish. So I ask you: Where do these functions come from? Who made them? Where are they published? All the places that they appear on the internet that I found point to you, so tell us who besides yourself knows them.

  • Ah yes, and looking for GEDI FS in google, came no relevant result. What bug is this?

  • pmg, exactly that, I switched the &text by text and it worked, thank you. When working with pointers received by parameters and a little different

  • Victor Stafusa, It’s part of an API of a piece of equipment that I use, just this one in the manual, I think, sorry

  • @Lucasfernandes Just out of curiosity, what is this equipment? I am intrigued that there is an API of some equipment that is so obscure.

  • @Victor Stafusa, it’s a POS machine, you know? Those card readers

Show 9 more comments

1 answer

1


void FileLer(char *texto, char *file)
{
    // ...
    ret = GEDI_FS_FileRead(FileHandleLer, &texto, &BufferLenLer);
    //                                    ^^^^^^
    // ...
}

&texto and texto are different things. The first has kind char **, the second has kind char *. The first points to a local variable to the function FileLer(), the second points to an external string.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.