Re: [PATCH 1/6] Add strbuf_rtrim and strbuf_insert.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Pierre Habouzit <madcoder@xxxxxxxxxx> writes:

> +void strbuf_insert(struct strbuf *sb, size_t pos, const void *data, size_t len) {
> +	strbuf_grow(sb, len);
> +	if (pos >= sb->len) {
> +		sb->len = pos;
> +	} else {
> +		memmove(sb->buf + pos + len, sb->buf + pos, sb->len - pos);
> +	}
> +	memcpy(sb->buf + pos, data, len);
> +	strbuf_setlen(sb, sb->len + len);
> +}
> +

What's the semantics of inserting way beyond len?  If the buf is
5-byte "ABCDE" currently and you insert "FG" at position 7, do
you get "ABCDE" + 2-byte undefined garbage + "FG" and result in
9-byte buffer?  Or "FG" is appended after position 5 and you get
"ABCDEFG" 7-byte buffer?

I personally think we should OOPS such a caller, but I suspect
you wanted the latter, in which case I think "sb->len = pos"
assignment is done in the wrong direction, in other words, it
should read "pos = sb->len" instead.

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux