Question

I have looked around for answer on various forums, tried various things and still getting this error:

warning: format not a string literal and no format arguments [-Wformat-security]

The compiler point to the line in the function that has the error, here's how it looks:

int print_notes(int fd, int uid, char *searchstring) {
    int note_length;
    char byte=0, note_buffer[100];

    note_length = find_user_note(fd, uid);
    if(note_length == -1)  // if end of file reached
        return 0;           //   return 0

    read(fd, note_buffer, note_length); // read note data
    note_buffer[note_length] = 0;       // terminate the string

    if(search_note(note_buffer, searchstring)) // if searchstring found
        scanf("%s", note_buffer) // Got this line from an answer in the forums
        printf(note_buffer);  // compiler points here
    return 1;
}

If you want the full code i can post it here, but its kind of long :/ don't know if that will be ok.

Was it helpful?

Solution

Its giving warning for :

printf(note_buffer);

As you are getting string being formed at runtime and trying to print it.

Use :

printf("%s",note_buffer);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top