I'm working on a crypter project and ran into the following error when attempting to compile the program.
main.cpp(520): error C4703: potentially uninitialized local pointer variable 'pNamesPtr' used
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
DLLNAMES[i].UsedAlready = 0;
}
*dwOutSize = (DWORD)pNamesPtr - (DWORD)pBuffer;//*<----is line 520 of error
*dwImportsSize = *dwOutSize - *dwIATSize;
return pBuffer;
}
#pragma pack(1)
typedef struct
Can someone help me with this error? Do you need more code in order to have a good answer?
This warning isn't always a bug, sometimes its just the result of an optimization. Since it is in your code and you don't know what is this it might actually be a bug.
For example if I write:
int i;
if (this_and_that)
i = 5;
if (whatever)
printf("%d\n", i); // <--- this may give a potential blahblah warning
If you are optimizing then you may know that the value of whatever
is always true when the value of this_and_that
is true so if printf
gets called then i
is already guaranteed to be initialized but the compiler often can not figure out the relation between this_and_that
and whatever
, this is why you get the warning. One possible quick fix to this warning is initializing the variable to a default value right where you declare it. In my opinion sparing with initialization is a bad practice and a source of a lot of bugs.
It means that
pNamesPtr
when you declare it, so it starts with an invalid value; andCheck all the code paths from the declaration to the point of use. Do they all assign something sensible to the variable? If not, fix it so they do.
If they do, and you're convinced that you're assigning it correctly, could you simplify the code so that it's obvious to the compiler that it is?
If all else fails, then you could silence the compiler by initialising it to nullptr
or some other default value in the initialisation. But only do that if you're really sure your code is correct - compilers are usually good at spotting mistakes like this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With