[or-cvs] r13623: fix bufs in buf_pos_t implementation. (in tor/trunk: . src/or)
nickm at seul.org
nickm at seul.org
Wed Feb 20 17:48:40 UTC 2008
Author: nickm
Date: 2008-02-20 12:48:39 -0500 (Wed, 20 Feb 2008)
New Revision: 13623
Modified:
tor/trunk/
tor/trunk/ChangeLog
tor/trunk/src/or/buffers.c
tor/trunk/src/or/test.c
Log:
r18264 at catbus: nickm | 2008-02-20 12:48:21 -0500
fix bufs in buf_pos_t implementation.
Property changes on: tor/trunk
___________________________________________________________________
svk:merge ticket from /tor/trunk [r18264] on 8246c3cf-6607-4228-993b-4d95d33730f1
Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog 2008-02-20 17:48:37 UTC (rev 13622)
+++ tor/trunk/ChangeLog 2008-02-20 17:48:39 UTC (rev 13623)
@@ -17,6 +17,8 @@
number we've gotten from accept(). This bug made us fail to count
all sockets that we were using for incoming connections. Bugfix on
0.2.0.x
+ - Fix code used to find strings within buffers, when those strings
+ are not in the first chunk of the buffer.
o Minor features (performance):
- Tune parameters for cell pool allocation to minimize amount of
Modified: tor/trunk/src/or/buffers.c
===================================================================
--- tor/trunk/src/or/buffers.c 2008-02-20 17:48:37 UTC (rev 13622)
+++ tor/trunk/src/or/buffers.c 2008-02-20 17:48:39 UTC (rev 13623)
@@ -998,9 +998,8 @@
/** Internal structure: represents a position in a buffer. */
typedef struct buf_pos_t {
const chunk_t *chunk; /**< Which chunk are we pointing to? */
- int pos; /**< Which character inside the chunk's data are we pointing to? */
- int pos_absolute; /**< Which character inside the buffer are we pointing to?
- */
+ off_t pos;/**< Which character inside the chunk's data are we pointing to? */
+ size_t chunk_pos; /**< Total length of all previous chunks. */
} buf_pos_t;
/** Initialize <b>out</b> to point to the first character of <b>buf</b>.*/
@@ -1009,7 +1008,7 @@
{
out->chunk = buf->head;
out->pos = 0;
- out->pos_absolute = 0;
+ out->chunk_pos = 0;
}
/** Advance <b>out</b> to the first appearance of <b>ch</b> at the current
@@ -1019,19 +1018,19 @@
buf_find_pos_of_char(char ch, buf_pos_t *out)
{
const chunk_t *chunk;
- int offset = 0; /*XXXX020 should this be pos_absolute? Otherwise, bug. */
int pos;
- tor_assert(out && out->chunk && out->pos < (int)out->chunk->datalen);
+ tor_assert(out);
+ if (out->chunk)
+ tor_assert(out->pos < out->chunk->datalen);
pos = out->pos;
for (chunk = out->chunk; chunk; chunk = chunk->next) {
char *cp = memchr(chunk->data+pos, ch, chunk->datalen-pos);
if (cp) {
out->chunk = chunk;
out->pos = cp - chunk->data;
- out->pos_absolute = offset + (cp - chunk->data);
- return out->pos_absolute;
+ return out->chunk_pos + out->pos;
} else {
- offset += chunk->datalen;
+ out->chunk_pos += chunk->datalen;
pos = 0;
}
}
@@ -1043,15 +1042,14 @@
static INLINE int
buf_pos_inc(buf_pos_t *pos)
{
- if ((size_t)pos->pos == pos->chunk->datalen) {
+ ++pos->pos;
+ if (pos->pos == pos->chunk->datalen) {
if (!pos->chunk->next)
return -1;
+ pos->chunk_pos += pos->chunk->datalen;
pos->chunk = pos->chunk->next;
pos->pos = 0;
- } else {
- ++pos->pos;
}
- ++pos->pos_absolute;
return 0;
}
@@ -1084,7 +1082,7 @@
buf_pos_init(buf, &pos);
while (buf_find_pos_of_char(*s, &pos) >= 0) {
if (buf_matches_at_pos(&pos, s, n)) {
- return pos.pos_absolute;
+ return pos.chunk_pos + pos.pos;
} else {
if (buf_pos_inc(&pos)<0)
return -1;
Modified: tor/trunk/src/or/test.c
===================================================================
--- tor/trunk/src/or/test.c 2008-02-20 17:48:37 UTC (rev 13622)
+++ tor/trunk/src/or/test.c 2008-02-20 17:48:39 UTC (rev 13623)
@@ -255,6 +255,8 @@
buf_free(buf);
buf_free(buf2);
+ /*XXXX020 Test code to find chars and strings on buffers. */
+
#if 0
{
int s;
More information about the tor-commits
mailing list