Reputation: 37
int main(int argc, char *argv[])
{
std::string first_arg = argv[1];
std:: string sec_arg = argv[2];
}
Buffer Overrun help This code reads past the end of the buffer pointed to by argv. The first byte read is at offset 8 from the beginning of the buffer pointed to by argv. The offset exceeds the capacity. The capacity of the buffer pointed to by argv, in bytes, is equal to 8.
Upvotes: 1
Views: 826
Reputation: 86
CodeSonar warns that there can be a buffer overrun as your program could be called with <2 arguments. If you check that argc>2 before you access argv, then this warning will go away:
#include <string>
int main(int argc, char *argv[])
{
if (argc>2)
{
std::string first_arg = argv[1];
std::string sec_arg = argv[2];
}
return 0;
}
Upvotes: 1