Compiler Warning 'pointer from integer w/o cast'

In a function that writes data to a file (using a custom fn writeAsText()), I call a function that parses the data from another file:

1
2
3
4
5
6
7
void writeBootup(FILE *filePtr, char *buffer, long linecount){
    static long count = 1;
    char *strBootup = getBootup(buffer);
    writeAsText(filePtr, "Report 4444 ", strBootup, linecount, count);
    free(&strBootup);
    count++;
}


The called fn:

1
2
3
4
5
6
7
8
9
10
11
12
13
getBootup(char* buffer){
    char *strBootup = NULL;
    char *strEnd    = NULL;
    long longBootup = 0;
    if(((strBootup = strstr(buffer, "< 4444")) != NULL) && ((strEnd = strstr(buffer, "\n")) != NULL)){
        long len = strEnd - (strBootup + OFFSET_BOOTUP);
        char *bootbuffer;
        bootbuffer = (char*) malloc(len+1);
        strncpy(bootbuffer, strBootup + OFFSET_BOOTUP, len);
        bootbuffer[len] = '\0';
        if(bootbuffer != NULL){return bootbuffer}
    }
}


You may recognize it from my other post... I have, at this point, three such functions (and have to write many more). The ideais to pass the pointer to an array from one function ot the other, and print the contents of the array. This works with two of three functions (despite the warnings), but this one crashes the program.

Upon compilation, I receive the following warning:
[Warning] initialization makes pointer from integer without a cast
I don't know exactly how I should cast here, and what exactly. If it's any help, I'm using Dev-C++ 4.9.9.2 with its standard compiler MingW32.
Last edited on
closed account (z05DSL3A)
Just a quick look over you code, getBootup returns bootbuffer if it is not NULL, What if it is NULL? What does the function return then?
Last edited on
I've indented your code to show my point
1
2
3
4
5
6
7
8
9
10
11
12
13
getBootup(char* buffer){
    char *strBootup = NULL;
    char *strEnd    = NULL;
    long longBootup = 0;
    if(((strBootup = strstr(buffer, "< 4444")) != NULL) && ((strEnd = strstr(buffer)) != NULL)){
        long len = strEnd - (strBootup + OFFSET_BOOTUP);
        char *bootbuffer;
        bootbuffer = (char*) malloc(len+1);
        strncpy(bootbuffer, strBootup + OFFSET_BOOTUP, len);
        bootbuffer[len] = '\0';
        if(bootbuffer != NULL){return bootbuffer}
    }
}

The only time you specify what you return is nested inside 2 if statements. Expanding on Grey Wolfs comments, you need to consider what gets returned in all the else cases.
Which line do you get the warning from?
First thing: Thank you for the replies :)

The problem with indentation is that in the web form, tab does not work, and the computer I code on is not connected to the company intranet... I'll edit it in notepad before posting next time.

The warning happens on line 3 in the function writeBootup(). BUt the crashes are probably due to the undefined else statements (which actually should not happen due to pre-filtering, but obviously, they do... I'll look into it tomorrow).

A sidenote: the function type of getBootup() is void.
What are you calling function type? If it's the return type then you can't return anything.

The line 3 warning I would guess at being you passing linecount or count as integers when the prototype for writeAsText() is specifying a pointer to an integer.

BTW I use 4 spaces rather than tabs for indenting when posting code.
In fn:
char *strBootup = getBootup(buffer);

Then u say:
A sidenote: the function type of getBootup() is void.


U mean:"i initiate strBootup with nothing?",then that will curse a fatal error(uninitiated pointer.)
Silly me meant char and typed void... of course the function is initialized as char *getBootup(). It was/is implemented as char * in my program, so that is not the problem, I think.
Here's the function prototype of void writeAsText():

void writeAsText(FILE *, char *, char *, long, long)
Last edited on
Well, now at least I found (and fixed) what made the program crash; I wonder if the warnings are really dangerous, though. Are they a stability risk?
Last edited on
closed account (z05DSL3A)
You should never ignore warnings, some of them can cause you big headaches further down the line.

I develop my code with warning set to the highest level, when I build a release I have warnings set to the highest level and "treat warning as errors" set. The aim is to get rid of all warnings, you may have to disable certain warning for parts of the code (usually third party/uneditable) or make minor changes to your code to make 'nuisance' warnings go away, but when that important warning pops up you will see it and deal with it before it causes you a problem.
My problem is, I can't seem to find what's causing the Warning, because I tried to make educated guesses to clear them, but I fear I just haven't understood how to correctly use pointers in their completeness, yet.
closed account (z05DSL3A)
In the line if(((strBootup = strstr(buffer, "< 4444")) != NULL) && ((strEnd = strstr(buffer)) != NULL)){, you use strEnd = strstr(buffer) is this correct? I am not aware a strstr only taking a single parameter.
I'm sorry, it's just an omission when I copied the line by typing (I really have to find another usb flash drive). It goes as follows:

(strEnd = strstr(buffer, "\n")) != NULL

(Altered in OP, as well.)
Topic archived. No new replies allowed.