Yep, I ported that piece of code to 'C', and this what I get:

User="user" Port="12345/folder" Path="/folder" Host="foo.no-ip.ba


I really feel like rewriting this code properly

#include <stdlib.h>
#include <string.h>
#include <assert.h>

int main()
{
        char uri[] = {"sftp://[email protected]:12345/folder"; };


        char *u, *h, *s, *p;
        char *h_end;

        assert (uri != NULL);

        u = strchr(uri, ':');
        assert (u != NULL);
        u+=3;

        p = strchr (u, '/');

        h = strchr(u, '@');

        if (h && (p == NULL || h < p)) {
                *h='\0';
                h++;
        } else {
                h = u;
                u = NULL;
        }

        s = strchr(h, ':');

        if (s && (p == NULL || s < p)) {
                h_end = s-1;
                *s = '\0';
                s++;
        } else {
                h_end = p;
                s = NULL;
        }

        if (h_end == NULL) {
                h_end = h + strlen(h);
        }


        
        printf("User=\"%s\" Port=\"%s\" Path=\"%s\" ",
                u, s, p);

        *h_end = '\0';

        printf("Host=\"%s\n\"", h);
}

-- 
nautilus crashed with SIGSEGV in strlen()
https://bugs.launchpad.net/bugs/333462
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.

-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to