summaryrefslogtreecommitdiff
path: root/interpolate.c
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2007-10-16 04:15:25 (GMT)
committerShawn O. Pearce <spearce@spearce.org>2007-10-16 04:15:25 (GMT)
commit2e13e5d89252ceef606a0a7be32dbf5bea7e5aca (patch)
tree91f34e2fa799880e917238a7794b3dde35536c09 /interpolate.c
parentccfc02a30057a5fa7376e1fc8e8c3fe5478556f4 (diff)
parentd55e7c3acf72413563e695a19f7f66efac442064 (diff)
downloadgit-2e13e5d89252ceef606a0a7be32dbf5bea7e5aca.zip
git-2e13e5d89252ceef606a0a7be32dbf5bea7e5aca.tar.gz
git-2e13e5d89252ceef606a0a7be32dbf5bea7e5aca.tar.bz2
Merge branch 'master' into db/fetch-pack
There's a number of tricky conflicts between master and this topic right now due to the rewrite of builtin-push. Junio must have handled these via rerere; I'd rather not deal with them again so I'm pre-merging master into the topic. Besides this topic somehow started to depend on the strbuf series that was in next, but is now in master. It no longer compiles on its own without the strbuf API. * master: (184 commits) Whip post 1.5.3.4 maintenance series into shape. Minor usage update in setgitperms.perl manual: use 'URL' instead of 'url'. manual: add some markup. manual: Fix example finding commits referencing given content. Fix wording in push definition. Fix some typos, punctuation, missing words, minor markup. manual: Fix or remove em dashes. Add a --dry-run option to git-push. Add a --dry-run option to git-send-pack. Fix in-place editing functions in convert.c instaweb: support for Ruby's WEBrick server instaweb: allow for use of auto-generated scripts Add 'git-p4 commit' as an alias for 'git-p4 submit' hg-to-git speedup through selectable repack intervals git-svn: respect Subversion's [auth] section configuration values gtksourceview2 support for gitview fix contrib/hooks/post-receive-email hooks.recipients error message Support cvs via git-shell rebase -i: use diff plumbing instead of porcelain ... Conflicts: Makefile builtin-push.c rsh.c
Diffstat (limited to 'interpolate.c')
-rw-r--r--interpolate.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/interpolate.c b/interpolate.c
index 0082677..6ef53f2 100644
--- a/interpolate.c
+++ b/interpolate.c
@@ -44,9 +44,8 @@ void interp_clear_table(struct interp *table, int ninterps)
* { "%%", "%"},
* }
*
- * Returns 0 on a successful substitution pass that fits in result,
- * Returns a number of bytes needed to hold the full substituted
- * string otherwise.
+ * Returns the length of the substituted string (not including the final \0).
+ * Like with snprintf, if the result is >= reslen, then it overflowed.
*/
unsigned long interpolate(char *result, unsigned long reslen,
@@ -61,8 +60,6 @@ unsigned long interpolate(char *result, unsigned long reslen,
int i;
char c;
- memset(result, 0, reslen);
-
while ((c = *src)) {
if (c == '%') {
/* Try to match an interpolation string. */
@@ -76,11 +73,15 @@ unsigned long interpolate(char *result, unsigned long reslen,
/* Check for valid interpolation. */
if (i < ninterps) {
value = interps[i].value;
- valuelen = strlen(value);
+ if (!value) {
+ src += namelen;
+ continue;
+ }
- if (newlen + valuelen + 1 < reslen) {
+ valuelen = strlen(value);
+ if (newlen + valuelen < reslen) {
/* Substitute. */
- strncpy(dest, value, valuelen);
+ memcpy(dest, value, valuelen);
dest += valuelen;
}
newlen += valuelen;
@@ -95,8 +96,9 @@ unsigned long interpolate(char *result, unsigned long reslen,
newlen++;
}
- if (newlen + 1 < reslen)
- return 0;
- else
- return newlen + 2;
+ /* XXX: the previous loop always keep room for the ending NUL,
+ we just need to check if there was room for a NUL in the first place */
+ if (reslen > 0)
+ *dest = '\0';
+ return newlen;
}