diff -Naur patchtool-0.1/list.c patchtool-0.2/list.c --- patchtool-0.1/list.c 2005-03-28 16:57:39.000000000 +0000 +++ patchtool-0.2/list.c 2005-03-28 19:45:08.000000000 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005 Vincent Hanquez + * Copyright (C) 2004 Vincent Hanquez * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published diff -Naur patchtool-0.1/parse.c patchtool-0.2/parse.c --- patchtool-0.1/parse.c 2005-03-28 18:40:39.000000000 +0000 +++ patchtool-0.2/parse.c 2005-03-31 22:11:23.000000000 +0000 @@ -42,6 +42,13 @@ int ret; int line_del, line_add, line_space; + if (!tmp || !*tmp) + return NULL; + if (strncmp(tmp, "@@ ", 2) != 0) { + fprintf(stderr, "error: hunk problem\n"); + return tmp + 1; + } + hunk = hunk_alloc(); if (!hunk) return tmp; @@ -51,8 +58,8 @@ ret = sscanf(tmp, "@@ -%d,%d +%d,%d @@", &hunk->off[0], &hunk->line[0], &hunk->off[1], &hunk->line[1]); if (ret != 4) { - fprintf(stderr, "error: not enough arg in hunk ?!\n"); - return tmp; + fprintf(stderr, "error: not enough arg in hunk: \"\"%.30s\"\"\n", tmp); + return tmp + 1; } tmp = strchr(tmp, '\n'); @@ -62,7 +69,8 @@ line_del = line_add = line_space = 0; - while (!((line_space + line_del == hunk->line[0]) && + while (tmp && *tmp && + !((line_space + line_del == hunk->line[0]) && (line_space + line_add == hunk->line[1]))) { if (strncmp(tmp, "@@ ", 3) == 0) { @@ -78,7 +86,8 @@ } tmp = strchr(tmp, '\n'); - tmp++; + if (tmp) + tmp++; } hunk->tlines[LINE_UNM] = line_space; @@ -102,6 +111,7 @@ part->start = tmp; if (strncmp(tmp, "--- ", 4) != 0) { + fprintf(stderr, "error: header problem\n"); return tmp; } @@ -110,6 +120,7 @@ tmp++; if (strncmp(tmp, "+++ ", 4) != 0) { + fprintf(stderr, "error: header problem\n"); return tmp; } @@ -117,7 +128,7 @@ tmp = strchr(tmp, '\n'); tmp++; - while ((strncmp(tmp, "@@ ", 3) == 0)) + while (tmp && *tmp && (strncmp(tmp, "@@ ", 3) == 0)) tmp = parse_hunk(p, part, tmp); part->end = tmp; @@ -137,8 +148,7 @@ p->addr = addr; p->len = len; - tmp = addr; - while (tmp < p->addr + p->len) { + for (tmp = addr; tmp && *tmp; ) { if (strncmp(tmp, "@@ ", 3) == 0) { fprintf(stderr, "error: no header before hunk\n"); break; @@ -146,11 +156,10 @@ if (strncmp(tmp, "--- ", 4) == 0) tmp = parse_part(p, tmp); - - tmp = strchr(tmp, '\n'); - if (!tmp) - break; - tmp++; + else { + tmp = strchr(tmp, '\n'); + if (tmp) tmp++; + } } return p;