[PATCH 13/19] ui-snapshot: use a struct strbuf instead of fixed-size buffers
John Keeping
john at keeping.me.uk
Sun Apr 7 15:37:42 CEST 2013
On Sun, Apr 07, 2013 at 03:25:36PM +0200, Jason A. Donenfeld wrote:
> On Sun, Apr 7, 2013 at 11:30 AM, John Keeping <john at keeping.me.uk> wrote:
> > + if (prefixcmp(snapshot.buf, reponame) == 0) {
> > + const char *new_start = snapshot.buf;
> > + new_start += strlen(reponame);
> > + while (new_start && (*new_start == '-' || *new_start == '_'))
> > + new_start++;
> > + strbuf_splice(&snapshot, 0, new_start - snapshot.buf, "", 0);
> > }
>
> Something funky is happening here.
Care to be more specific? I think this behaviour is the same as the
code it replaces - we're removing the leading reponame and any following
'-' or '_' characters from the start of snapshot:
- if (prefixcmp(snapshot, reponame) == 0) {
- snapshot += strlen(reponame);
- while (snapshot && (*snapshot == '-' || *snapshot == '_'))
- snapshot++;
+ if (prefixcmp(snapshot.buf, reponame) == 0) {
+ const char *new_start = snapshot.buf;
+ new_start += strlen(reponame);
+ while (new_start && (*new_start == '-' || *new_start == '_'))
+ new_start++;
+ strbuf_splice(&snapshot, 0, new_start - snapshot.buf, "", 0);
}
The strbuf_splice ends up just shifting the start of snapshot left by
"new_start - snapshot.buf" bytes, which is precisely the same as
changing the pointer to point at new_start (except that we can continue
to perform strbuf operations).
Of course, the following code is completely bogus :-(
+ strbuf_reset(&snapshot);
+ strbuf_addf(&snapshot, "v%s", snapshot.buf);
I'll fix that.
More information about the CGit
mailing list