summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYann Dirson <ydirson@altern.org>2006-06-17 14:16:38 +0200
committerYann Dirson <ydirson@altern.org>2006-06-17 14:16:38 +0200
commit33357c6940d204acac23d9e7ae369d071ce61a01 (patch)
tree961d5a5bc5cc60189ce42fe390842546d530fc20
parent5991e8b0acf1dbe3487c1f246a1d215b346a61f0 (diff)
downloadcvsps-33357c6940d204acac23d9e7ae369d071ce61a01.tar.gz
Get rid of strsep in cache.c, avoid useless copytest
This destructive parsing is bad, as shown by the fact that its mere use in the code makes tuning the parser a hell. So let's drop it before going further. This also removes the need to memcpy the buffer, since we won't be modifying it. Note: there are also loads of strsep() calls in cvs_direct.c to get rid of.
-rw-r--r--cache.c38
1 files changed, 20 insertions, 18 deletions
diff --git a/cache.c b/cache.c
index 01a8ed3..5f67a7c 100644
--- a/cache.c
+++ b/cache.c
@@ -365,7 +365,7 @@ enum
CR_BRANCH_POINT
};
-static void parse_cache_revision(PatchSetMember * psm, const char * p_buff)
+static void parse_cache_revision(PatchSetMember * psm, const char * buff)
{
/* The format used to generate is:
* "file:%s; pre_rev:%s; post_rev:%s; dead:%d; branch_point:%d\n"
@@ -375,35 +375,37 @@ static void parse_cache_revision(PatchSetMember * psm, const char * p_buff)
char post[REV_STR_MAX];
int dead = 0;
int bp = 0;
- char buff[BUFSIZ];
int state = CR_FILENAME;
- const char *s;
- char * p = buff;
-
- strcpy(buff, p_buff);
+ const char *sep;
+ char * p;
+ char * c;
- while ((s = strsep(&p, ";")))
+ for (p = buff, sep = buff; /* just ensure sep is non-NULL */
+ (sep != NULL) && (c = strchr(p, ':'));
+ p = sep + 1)
{
- char * c = strchr(s, ':');
-
- if (!c)
- {
- debug(DEBUG_APPERROR, "invalid cache revision line '%s'|'%s'", p_buff, s);
- exit(1);
- }
+ size_t len;
+ sep = strchr(c, ';');
+ c++;
- *c++ = 0;
+ if (sep != NULL)
+ len = sep - c;
+ else /* last field in the cache line */
+ len = strlen(c);
switch(state)
{
case CR_FILENAME:
- strcpy(filename, c);
+ memcpy(filename, c, len);
+ filename[len] = '\0';
break;
case CR_PRE_REV:
- strcpy(pre, c);
+ memcpy(pre, c, len);
+ pre[len] = '\0';
break;
case CR_POST_REV:
- strcpy(post, c);
+ memcpy(post, c, len);
+ post[len] = '\0';
break;
case CR_DEAD:
dead = atoi(c);