[H-GEN] malloc() causing a segfault

Nikolai Lusan nikolai at humbug.org.au
Wed Aug 30 23:51:41 EDT 2000


[ Humbug *General* list - semi-serious discussions about Humbug and ]
[ Unix-related topics.  Please observe the list's charter.          ]



Raymond Smith wrote:

> Indeed. What does the code in the middle do? Be careful of system/library

I admit I should have posted the entire procedure, but it's so piddly I didn't
think it worth it. It's a part of a general utility module I wrote while
getting my C stuff back together:

int strStripSpace(char *text)
{
        int start;
        char *tmp;

        tmp = (char *) malloc(sizeof(char) * 1025);

        for (start = 0; text[start] != '\0'; start++)
                if (!isspace(text[start]))
                                break;

        strncpy(tmp, text+start, 1025);
        strncpy(text, tmp, 1025);

        if (tmp != NULL)
                free(tmp);

        return 0;
}


basically it strips lead spaces from a line of text, yes I know is clumsy but
part of it was getting me back to pointers :)

Nikolai


--
* This is list (humbug) general handled by majordomo at lists.humbug.org.au .
* Postings to this list are only accepted from subscribed addresses of
* lists 'general' or 'general-post'.



More information about the General mailing list