Hello,
This code crashes with segfault
{
static char ip[1000], s[1000];
strcpy(s, line.toLocal8Bit().constData());
char *p1 = strstr(s, "client ") + 7, *p2 = ip;
while (*p1 && *p1 != ']')
*p2++ = *p1++;
*p2 = 0;
return ip;
QString MainWindowImpl::getIp(QString line)
{
static char ip[1000], s[1000];
strcpy(s, line.toLocal8Bit().constData());
char *p1 = strstr(s, "client ") + 7, *p2 = ip;
while (*p1 && *p1 != ']')
*p2++ = *p1++;
*p2 = 0;
return ip;
To copy to clipboard, switch view to plain text mode
If I change the line with strstr to:
char *p1 = s + 7, *p2 = ip;
char *p1 = s + 7, *p2 = ip;
To copy to clipboard, switch view to plain text mode
all is well..
I know I can do things the qt way but I want to be portable with plain c strings.
Thanks.
Bookmarks