[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] global segmentation fault
From: |
Hideki IWAMOTO |
Subject: |
[PATCH] global segmentation fault |
Date: |
Sun, 18 May 2003 02:39:30 +0900 |
When -c option of gtags is used, tags files are not updated
and -t option of global is used, segmentation fault often occurs.
>global -t ".*" > /dev/null
Segmentation fault
[current cvs version]
case1: Two or more spaces are in the last of string.
* Initial status.
* +------------------------------------------------------
* line |main 100 ./main.c \0
*
* The result of split(line, 4, list).
*
* +------------------------------------------------------
* list line |main\0 100\0 ./main.c\0 \0
* +---------+ ^ ^ ^ ^ ^ ^ ^
* |npart=4 | | | | | | | |
* +---------+ | | | | | | |
* | start *----+ | | | | | |
* | end *--------+ | | | | |
* | save ' '| | | | | |
* +---------+ | | | | |
* | start *-----------------+ | | | |
* | end *--------------------+ | | |
* | save ' '| | | |
* +---------+ | | |
* | start *------------------------+ | |
* | end *--------------------------------+ |
* | save ' '| |
* +---------+ |
* | start *-----------------------------------+
* | end *--+
* | save '\0' |
* +---------+ =
case2: One space is in the last of string.
If recover is called after split, access to an unspecified address occurs.
* Initial status.
* +------------------------------------------------------
* line |main 100 ./main.c \0
*
* The result of split(line, 4, list).
*
* +------------------------------------------------------
* list line |main\0 100\0 ./main.c\0\0
* +---------+ ^ ^ ^ ^ ^ ^
* |npart=4 | | | | | | |
* +---------+ | | | | | |
* | start *----+ | | | | |
* | end *--------+ | | | |
* | save ' '| | | | |
* +---------+ | | | |
* | start *-----------------+ | | |
* | end *--------------------+ | |
* | save ' '| | |
* +---------+ | |
* | start *------------------------+ |
* | end *--------------------------------+
* | save ' '|
* +---------+
* | start *-----> ????
* | end *-----> ????
* | save ???
* +---------+
[patched version]
case1:
same as current cvs version
case2:
* Initial status.
* +------------------------------------------------------
* line |main 100 ./main.c \0
*
* The result of split(line, 4, list).
*
* +------------------------------------------------------
* list line |main\0 100\0 ./main.c\0\0
* +---------+ ^ ^ ^ ^ ^ ^ ^
* |npart=4 | | | | | | | |
* +---------+ | | | | | | |
* | start *----+ | | | | | |
* | end *--------+ | | | | |
* | save ' '| | | | | |
* +---------+ | | | | |
* | start *-----------------+ | | | |
* | end *--------------------+ | | |
* | save ' '| | | |
* +---------+ | | |
* | start *------------------------+ | |
* | end *--------------------------------+ |
* | save ' '| |
* +---------+ |
* | start *----------------------------------+
* | end *--+
* | save '\0' |
* +---------+ =
Index: libutil/split.c
===================================================================
RCS file: /cvsroot/global/global/libutil/split.c,v
retrieving revision 1.7
diff -u -r1.7 split.c
--- libutil/split.c 27 Apr 2003 03:21:45 -0000 1.7
+++ libutil/split.c 17 May 2003 17:01:07 -0000
@@ -78,36 +78,38 @@
SPLIT *list;
{
char *s = line;
- struct part *part;
+ struct part *part = &list->part[0];
int count;
if (npart > NPART)
npart = NPART;
npart--;
- for (count = 0; count < npart; count++) {
+ for (count = 0; *s && count < npart; count++) {
while (*s && isblank(*s))
s++;
if (*s == '\0')
break;
- part = &list->part[count];
part->start = s;
while (*s && !isblank(*s))
s++;
part->end = s;
part->savec = *s;
- if (*s == '\0')
- break;
- *s++ = '\0';
+ part++;
}
if (*s) {
while (*s && isblank(*s))
s++;
- part = &list->part[count];
part->start = s;
part->end = (char *)0;
part->savec = 0;
+ count++;
+ part++;
+ }
+ while (part-- > &list->part[0]) {
+ if (part->savec != '\0')
+ *part->end = '\0';
}
- return list->npart = count + 1;
+ return list->npart = count;
}
/*
* recover: recover initial status of line.
----
Hideki IWAMOTO address@hidden
- [PATCH] global segmentation fault,
Hideki IWAMOTO <=