From: Junio C Hamano <gitster@pobox.com>
To: Pierre Habouzit <madcoder@debian.org>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] New strbuf APIs: splice and embed.
Date: Sat, 15 Sep 2007 17:57:44 -0700 [thread overview]
Message-ID: <7vwsur77g7.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: 20070915141335.ECB4B4C152@madism.org
Pierre Habouzit <madcoder@debian.org> writes:
> * strbuf_splice replace a portion of the buffer with another.
> * strbuf_embed replace a strbuf buffer with the given one, that should be
> malloc'ed. Then it enforces strbuf's invariants. If alloc > len, then this
> function has negligible cost, else it will perform a realloc, possibly
> with a cost.
"embed" does not sound quite right, does it? It is a reverse
operation of strbuf_detach() as far as I can tell.
> -void strbuf_rtrim(struct strbuf *sb)
> -{
> +void strbuf_rtrim(struct strbuf *sb) {
> while (sb->len > 0 && isspace((unsigned char)sb->buf[sb->len - 1]))
> sb->len--;
> sb->buf[sb->len] = '\0';
This is changing the style in the wrong direction, isn't it? We
start our functions like this:
type name(proto)
{
...
> +void strbuf_splice(struct strbuf *sb, size_t pos, size_t len,
> + const void *data, size_t dlen)
> +{
> + if (pos + len < pos)
> + die("you want to splice outside from the buffer");
That is a funny error message for an integer wrap-around check.
> + if (pos > sb->len)
> + pos = sb->len;
Shouldn't this be flagged as a programming error?
> + if (pos + len > sb->len)
> + len = sb->len - pos;
Likewise.
By the way, this is the kind of situation I wish everybody wrote
their comparison in textual order. I had to draw a picture like
this to see what was going on.
sb->buf
xxxxxxxxxxxzzzzzxxxxxxxxxxx\0
^ ^
0 sb->len
^ ^ ^ ^
pos pos+len pos pos+len
v v
yyyyyyyyyy yyyyyyyyyy
^ ^
dlen dlen
------------- --------------
pos < sb->len sb->len < pos
next prev parent reply other threads:[~2007-09-16 0:57 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-15 14:12 [RFC] strbuf's in builtin-apply Pierre Habouzit
2007-09-15 13:56 ` [PATCH] New strbuf APIs: splice and embed Pierre Habouzit
2007-09-16 0:57 ` Junio C Hamano [this message]
2007-09-16 8:10 ` Pierre Habouzit
2007-09-15 14:04 ` [PATCH] builtin-apply: use strbuf's instead of buffer_desc's Pierre Habouzit
2007-09-16 0:56 ` Junio C Hamano
2007-09-16 8:15 ` Pierre Habouzit
2007-09-15 17:07 ` [RFC] strbuf's in builtin-apply Pierre Habouzit
2007-09-16 17:21 ` Pierre Habouzit
2007-09-15 13:56 ` [PATCH] Now that cache.h needs strbuf.h, remove useless includes Pierre Habouzit
2007-09-15 13:56 ` [PATCH] New strbuf APIs: splice and attach Pierre Habouzit
2007-09-16 20:20 ` Florian Weimer
2007-09-16 20:51 ` Pierre Habouzit
2007-09-17 5:43 ` Florian Weimer
2007-09-15 21:50 ` [PATCH] Refactor replace_encoding_header Pierre Habouzit
2007-09-16 8:19 ` [PATCH] Remove preemptive allocations Pierre Habouzit
2007-09-16 13:51 ` [PATCH] Rewrite convert_to_{git,working_tree} to use strbuf's Pierre Habouzit
2007-09-16 18:27 ` Linus Torvalds
2007-09-16 16:54 ` [PATCH] builtin-apply: use strbuf's instead of buffer_desc's Pierre Habouzit
2007-09-16 17:28 ` [RFC] strbuf's in builtin-apply Pierre Habouzit
2007-09-16 22:54 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vwsur77g7.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=madcoder@debian.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).