[dovecot-cvs] dovecot/src/lib base64.c, 1.10, 1.11 base64.h, 1.10,
1.11 buffer.c, 1.20, 1.21 buffer.h, 1.11, 1.12 hex-binary.c,
1.7, 1.8 hex-binary.h, 1.7, 1.8 ostream-crlf.c, 1.7, 1.8 str.c,
1.14, 1.15
cras at dovecot.org
cras at dovecot.org
Fri Oct 8 20:51:50 EEST 2004
Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv10130/lib
Modified Files:
base64.c base64.h buffer.c buffer.h hex-binary.c hex-binary.h
ostream-crlf.c str.c
Log Message:
Buffer API change: we no longer support limited sized buffers where
writes past limit wouldn't kill the process. They weren't used hardly
anywhere, they could have hidden bugs and the code for handling them was too
complex.
This also changed base64 and hex-binary APIs.
Index: base64.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/base64.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- base64.c 15 Sep 2004 13:19:47 -0000 1.10
+++ base64.c 8 Oct 2004 17:51:48 -0000 1.11
@@ -46,7 +46,7 @@
static const char basis_64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-int base64_encode(const void *src, size_t src_size, buffer_t *dest)
+void base64_encode(const void *src, size_t src_size, buffer_t *dest)
{
const unsigned char *src_c = src;
size_t src_pos;
@@ -54,36 +54,28 @@
for (src_pos = 0; src_pos < src_size; ) {
c1 = src_c[src_pos++];
- if (buffer_append_c(dest, basis_64[c1 >> 2]) != 1)
- return 0;
+ buffer_append_c(dest, basis_64[c1 >> 2]);
c2 = src_pos == src_size ? 0 : src_c[src_pos];
- if (buffer_append_c(dest, basis_64[((c1 & 0x03) << 4) |
- ((c2 & 0xf0) >> 4)]) != 1)
- return 0;
+ buffer_append_c(dest, basis_64[((c1 & 0x03) << 4) |
+ ((c2 & 0xf0) >> 4)]);
if (src_pos++ == src_size) {
- if (buffer_append(dest, "==", 2) != 2)
- return 0;
+ buffer_append(dest, "==", 2);
break;
}
c3 = src_pos == src_size ? 0 : src_c[src_pos];
- if (buffer_append_c(dest, basis_64[((c2 & 0x0f) << 2) |
- ((c3 & 0xc0) >> 6)]) != 1)
- return 0;
+ buffer_append_c(dest, basis_64[((c2 & 0x0f) << 2) |
+ ((c3 & 0xc0) >> 6)]);
if (src_pos++ == src_size) {
- if (buffer_append_c(dest, '=') != 1)
- return 0;
+ buffer_append_c(dest, '=');
break;
}
- if (buffer_append_c(dest, basis_64[c3 & 0x3f]) != 1)
- return 0;
+ buffer_append_c(dest, basis_64[c3 & 0x3f]);
}
-
- return 1;
}
#define XX 127
@@ -115,7 +107,7 @@
size_t src_pos;
unsigned char buf[4];
int c1, c2, c3, c4;
- size_t ret, size;
+ size_t size;
for (src_pos = 0; src_pos+3 < src_size; ) {
c1 = src_c[src_pos++];
@@ -156,17 +148,7 @@
}
}
- ret = buffer_append(dest, buf, size);
- if (ret != size) {
- /* buffer full */
- if (src_pos_r != NULL) {
- *src_pos_r = src_pos-4;
- ret = buffer_get_used_size(dest) - (size-ret);
- buffer_set_used_size(dest, ret);
- }
- return 0;
- }
-
+ buffer_append(dest, buf, size);
if (size < 3) {
/* end of base64 data */
break;
@@ -176,5 +158,5 @@
if (src_pos_r != NULL)
*src_pos_r = src_pos;
- return 1;
+ return 0;
}
Index: base64.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/base64.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- base64.h 15 Sep 2004 13:19:47 -0000 1.10
+++ base64.h 8 Oct 2004 17:51:48 -0000 1.11
@@ -1,14 +1,13 @@
#ifndef __BASE64_H
#define __BASE64_H
-/* Translates binary data into base64. The src must not point to dest buffer.
- Returns 1 if all ok, 0 if dest buffer got full. */
-int base64_encode(const void *src, size_t src_size, buffer_t *dest);
+/* Translates binary data into base64. The src must not point to dest buffer. */
+void base64_encode(const void *src, size_t src_size, buffer_t *dest);
/* Translates base64 data into binary and appends it to dest buffer. dest may
- point to same buffer as src. Returns 1 if all ok, 0 if dest buffer got full
- or -1 if data is invalid. Any CR, LF characters are ignored, as well as
- whitespace at beginning or end of line.
+ point to same buffer as src. Returns 0 if all ok, -1 if data is invalid.
+ Any CR, LF characters are ignored, as well as whitespace at beginning or
+ end of line.
This function may be called multiple times for parsing the same stream.
If src_pos is non-NULL, it's updated to first non-translated character in
Index: buffer.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/buffer.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- buffer.c 8 Oct 2004 16:59:45 -0000 1.20
+++ buffer.c 8 Oct 2004 17:51:48 -0000 1.21
@@ -12,12 +12,12 @@
/* private: */
unsigned char *w_buffer;
- size_t dirty, alloc, max_alloc;
+ size_t dirty, alloc;
pool_t pool;
unsigned int alloced:1;
- unsigned int hard:1;
+ unsigned int dynamic:1;
};
static void buffer_alloc(struct real_buffer *buf, size_t size)
@@ -36,84 +36,47 @@
buf->alloced = TRUE;
}
-static int buffer_check_read(const struct real_buffer *buf,
- size_t *pos, size_t *data_size)
-{
- size_t max_size;
-
- if (*pos >= buf->used)
- return FALSE;
-
- max_size = buf->used - *pos;
- if (*data_size > max_size)
- *data_size = max_size;
- return TRUE;
-}
-
-static inline int
-buffer_check_limits(struct real_buffer *buf, size_t pos, size_t *data_size,
- int accept_partial)
+static inline void
+buffer_check_limits(struct real_buffer *buf, size_t pos, size_t data_size)
{
- size_t new_size, alloc_size;
-
- /* make sure we're within our limits */
- if (pos >= buf->max_alloc ||
- buf->max_alloc - pos < *data_size) {
- if (buf->hard) {
- i_panic("Buffer full (%"PRIuSIZE_T" > "
- "%"PRIuSIZE_T")", pos + *data_size,
- buf->max_alloc);
- }
-
- if (!accept_partial || pos >= buf->max_alloc)
- return FALSE;
+ size_t new_size;
- *data_size = buf->max_alloc - pos;
+ if ((size_t)-1 - pos < data_size) {
+ i_panic("Buffer write out of range (%"PRIuSIZE_T
+ " + %"PRIuSIZE_T")", pos, data_size);
}
- new_size = pos + *data_size;
+ new_size = pos + data_size;
- /* see if we need to grow the buffer */
if (new_size > buf->alloc) {
- alloc_size = nearest_power(new_size);
- if (alloc_size > buf->max_alloc)
- alloc_size = buf->max_alloc;
+ if (!buf->dynamic) {
+ i_panic("Buffer full (%"PRIuSIZE_T" > %"PRIuSIZE_T")",
+ pos + data_size, buf->alloc);
+ }
- if (alloc_size != buf->alloc)
- buffer_alloc(buf, alloc_size);
+ buffer_alloc(buf, nearest_power(new_size));
}
if (new_size > buf->used)
buf->used = new_size;
- return TRUE;
}
-buffer_t *buffer_create_static(pool_t pool, size_t size)
+buffer_t *buffer_create_static_hard(pool_t pool, size_t size)
{
struct real_buffer *buf;
buf = p_new(pool, struct real_buffer, 1);
buf->pool = pool;
- buf->max_alloc = size;
buffer_alloc(buf, size);
return (buffer_t *)buf;
}
-buffer_t *buffer_create_static_hard(pool_t pool, size_t size)
-{
- buffer_t *buf;
-
- buf = buffer_create_static(pool, size);
- ((struct real_buffer *)buf)->hard = TRUE;
- return buf;
-}
-
buffer_t *buffer_create_data(pool_t pool, void *data, size_t size)
{
struct real_buffer *buf;
buf = p_new(pool, struct real_buffer, 1);
buf->pool = pool;
- buf->alloc = buf->max_alloc = size;
+ buf->alloc = size;
buf->r_buffer = buf->w_buffer = data;
return (buffer_t *)buf;
}
@@ -124,18 +87,18 @@
buf = p_new(pool, struct real_buffer, 1);
buf->pool = pool;
- buf->used = buf->alloc = buf->max_alloc = size;
+ buf->used = buf->alloc = size;
buf->r_buffer = data;
return (buffer_t *)buf;
}
-buffer_t *buffer_create_dynamic(pool_t pool, size_t init_size, size_t max_size)
+buffer_t *buffer_create_dynamic(pool_t pool, size_t init_size)
{
struct real_buffer *buf;
buf = p_new(pool, struct real_buffer, 1);
buf->pool = pool;
- buf->max_alloc = max_size;
+ buf->dynamic = TRUE;
buffer_alloc(buf, init_size);
return (buffer_t *)buf;
}
@@ -168,49 +131,44 @@
buf->used = 0;
}
-size_t buffer_write(buffer_t *_buf, size_t pos,
- const void *data, size_t data_size)
+void buffer_write(buffer_t *_buf, size_t pos,
+ const void *data, size_t data_size)
{
struct real_buffer *buf = (struct real_buffer *)_buf;
- if (!buffer_check_limits(buf, pos, &data_size, TRUE))
- return 0;
-
+ buffer_check_limits(buf, pos, data_size);
memcpy(buf->w_buffer + pos, data, data_size);
- return data_size;
}
-size_t buffer_append(buffer_t *buf, const void *data, size_t data_size)
+void buffer_append(buffer_t *buf, const void *data, size_t data_size)
{
- return buffer_write(buf, buf->used, data, data_size);
+ buffer_write(buf, buf->used, data, data_size);
}
-size_t buffer_append_c(buffer_t *buf, unsigned char chr)
+void buffer_append_c(buffer_t *buf, unsigned char chr)
{
- return buffer_append(buf, &chr, 1);
+ buffer_append(buf, &chr, 1);
}
-size_t buffer_insert(buffer_t *_buf, size_t pos,
- const void *data, size_t data_size)
+void buffer_insert(buffer_t *_buf, size_t pos,
+ const void *data, size_t data_size)
{
struct real_buffer *buf = (struct real_buffer *)_buf;
- size_t size;
if (pos >= buf->used)
return buffer_write(_buf, pos, data, data_size);
- size = buffer_copy(_buf, pos + data_size, _buf, pos, (size_t)-1);
+ buffer_copy(_buf, pos + data_size, _buf, pos, (size_t)-1);
memcpy(buf->w_buffer + pos, data, data_size);
- return size;
}
-size_t buffer_delete(buffer_t *_buf, size_t pos, size_t size)
+void buffer_delete(buffer_t *_buf, size_t pos, size_t size)
{
struct real_buffer *buf = (struct real_buffer *)_buf;
size_t end_size;
if (pos >= buf->used)
- return 0;
+ return;
end_size = buf->used - pos;
if (size < end_size) {
@@ -220,55 +178,50 @@
buf->w_buffer + pos + size, end_size);
} else {
/* delete the rest of the buffer */
- size = end_size;
end_size = 0;
}
buffer_set_used_size(_buf, pos + end_size);
- return size;
}
-size_t buffer_write_zero(buffer_t *_buf, size_t pos, size_t data_size)
+void buffer_write_zero(buffer_t *_buf, size_t pos, size_t data_size)
{
struct real_buffer *buf = (struct real_buffer *)_buf;
- if (!buffer_check_limits(buf, pos, &data_size, TRUE))
- return 0;
-
+ buffer_check_limits(buf, pos, data_size);
memset(buf->w_buffer + pos, 0, data_size);
- return data_size;
}
-size_t buffer_append_zero(buffer_t *buf, size_t data_size)
+void buffer_append_zero(buffer_t *buf, size_t data_size)
{
- return buffer_write_zero(buf, buf->used, data_size);
+ buffer_write_zero(buf, buf->used, data_size);
}
-size_t buffer_insert_zero(buffer_t *_buf, size_t pos, size_t data_size)
+void buffer_insert_zero(buffer_t *_buf, size_t pos, size_t data_size)
{
struct real_buffer *buf = (struct real_buffer *)_buf;
- size_t size;
if (pos >= buf->used)
return buffer_write_zero(_buf, pos, data_size);
- size = buffer_copy(_buf, pos + data_size, _buf, pos, (size_t)-1);
+ buffer_copy(_buf, pos + data_size, _buf, pos, (size_t)-1);
memset(buf->w_buffer + pos, 0, data_size);
- return size;
}
-size_t buffer_copy(buffer_t *_dest, size_t dest_pos,
- const buffer_t *_src, size_t src_pos, size_t copy_size)
+void buffer_copy(buffer_t *_dest, size_t dest_pos,
+ const buffer_t *_src, size_t src_pos, size_t copy_size)
{
struct real_buffer *dest = (struct real_buffer *)_dest;
struct real_buffer *src = (struct real_buffer *)_src;
+ size_t max_size;
- if (!buffer_check_read(src, &src_pos, ©_size))
- return 0;
+ i_assert(src_pos <= src->used);
- if (!buffer_check_limits(dest, dest_pos, ©_size, TRUE))
- return 0;
+ max_size = src->used - src_pos;
+ if (copy_size > max_size)
+ copy_size = max_size;
+ buffer_check_limits(dest, dest_pos, copy_size);
if (src == dest) {
memmove(dest->w_buffer + dest_pos,
src->r_buffer + src_pos, copy_size);
@@ -276,22 +229,19 @@
memcpy(dest->w_buffer + dest_pos,
src->r_buffer + src_pos, copy_size);
}
- return copy_size;
}
-size_t buffer_append_buf(buffer_t *dest, const buffer_t *src,
- size_t src_pos, size_t copy_size)
+void buffer_append_buf(buffer_t *dest, const buffer_t *src,
+ size_t src_pos, size_t copy_size)
{
- return buffer_copy(dest, dest->used, src, src_pos, copy_size);
+ buffer_copy(dest, dest->used, src, src_pos, copy_size);
}
void *buffer_get_space_unsafe(buffer_t *_buf, size_t pos, size_t size)
{
struct real_buffer *buf = (struct real_buffer *)_buf;
- if (!buffer_check_limits(buf, pos, &size, FALSE))
- return NULL;
-
+ buffer_check_limits(buf, pos, size);
return buf->w_buffer + pos;
}
@@ -327,41 +277,3 @@
return buf->alloc;
}
-
-#ifdef BUFFER_TEST
-/* gcc buffer.c -o testbuffer liblib.a -Wall -DHAVE_CONFIG_H -DBUFFER_TEST -g */
-int main(void)
-{
- buffer_t *buf;
- char data[12], *bufdata;
- size_t bufsize;
-
- lib_init();
-
- memset(data, '!', sizeof(data));
- bufdata = data + 1;
- bufsize = sizeof(data)-2;
-
- buf = buffer_create_data(system_pool, bufdata, bufsize);
- i_assert(buffer_write(buf, 5, "12345", 5) == 5);
- i_assert(buf->used == 10);
- i_assert(buffer_write(buf, 6, "12345", 5) == 4);
- i_assert(buf->used == 10);
-
- buf = buffer_create_data(system_pool, bufdata, bufsize);
- i_assert(buffer_write(buf, 0, "1234567890", 10) == 10);
- i_assert(buffer_write(buf, 0, "12345678901", 11) == 10);
- i_assert(buffer_append(buf, "1", 1) == 0);
- i_assert(buf->used == 10);
-
- buf = buffer_create_data(system_pool, bufdata, bufsize);
- i_assert(buffer_append(buf, "12345", 5) == 5);
- i_assert(buf->used == 5);
- i_assert(buffer_append(buf, "123456", 6) == 5);
- i_assert(buf->used == 10);
-
- i_assert(data[0] == '!');
- i_assert(data[sizeof(data)-1] == '!');
- return 0;
-}
-#endif
Index: buffer.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/buffer.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- buffer.h 3 Oct 2004 16:30:18 -0000 1.11
+++ buffer.h 8 Oct 2004 17:51:48 -0000 1.12
@@ -11,9 +11,6 @@
realloc()ed. You shouldn't rely on it being valid if you have modified
buffer in any way. */
-/* Create a static sized buffer. Writes past this size will simply not
- succeed. */
-buffer_t *buffer_create_static(pool_t pool, size_t size);
/* Create a static sized buffer. Writes past this size will kill the program. */
buffer_t *buffer_create_static_hard(pool_t pool, size_t size);
/* Create a modifyable buffer from given data. */
@@ -22,7 +19,7 @@
buffer_t *buffer_create_const_data(pool_t pool, const void *data, size_t size);
/* Creates a dynamically growing buffer. Whenever write would exceed the
current size it's grown. */
-buffer_t *buffer_create_dynamic(pool_t pool, size_t init_size, size_t max_size);
+buffer_t *buffer_create_dynamic(pool_t pool, size_t init_size);
/* Free the memory used by buffer. Not needed if the memory is free'd
directly from the memory pool. */
void buffer_free(buffer_t *buf);
@@ -33,43 +30,41 @@
/* Reset the buffer. used size and it's contents are zeroed. */
void buffer_reset(buffer_t *buf);
-/* Write data to buffer at specified position, returns number of bytes
- written. */
-size_t buffer_write(buffer_t *buf, size_t pos,
- const void *data, size_t data_size);
-/* Append data to buffer, returns number of bytes written. */
-size_t buffer_append(buffer_t *buf, const void *data, size_t data_size);
-/* Append character to buffer, returns 1 if written, 0 if not. */
-size_t buffer_append_c(buffer_t *buf, unsigned char chr);
+/* Write data to buffer at specified position. */
+void buffer_write(buffer_t *buf, size_t pos,
+ const void *data, size_t data_size);
+/* Append data to buffer. */
+void buffer_append(buffer_t *buf, const void *data, size_t data_size);
+/* Append character to buffer. */
+void buffer_append_c(buffer_t *buf, unsigned char chr);
-/* Insert data to buffer, returns number of bytes inserted. */
-size_t buffer_insert(buffer_t *buf, size_t pos,
- const void *data, size_t data_size);
-/* Delete data from buffer, returns number of bytes deleted. */
-size_t buffer_delete(buffer_t *buf, size_t pos, size_t size);
+/* Insert data to buffer. */
+void buffer_insert(buffer_t *buf, size_t pos,
+ const void *data, size_t data_size);
+/* Delete data from buffer. */
+void buffer_delete(buffer_t *buf, size_t pos, size_t size);
/* Fill buffer with zero bytes. */
-size_t buffer_write_zero(buffer_t *buf, size_t pos, size_t data_size);
-size_t buffer_append_zero(buffer_t *buf, size_t data_size);
-size_t buffer_insert_zero(buffer_t *buf, size_t pos, size_t data_size);
+void buffer_write_zero(buffer_t *buf, size_t pos, size_t data_size);
+void buffer_append_zero(buffer_t *buf, size_t data_size);
+void buffer_insert_zero(buffer_t *buf, size_t pos, size_t data_size);
/* Copy data from buffer to another. The buffers may be same in which case
it's internal copying, possibly with overlapping positions (ie. memmove()
like functionality). copy_size may be set to (size_t)-1 to copy the rest of
- the used data in buffer. Returns the number of bytes actually copied. */
-size_t buffer_copy(buffer_t *dest, size_t dest_pos,
- const buffer_t *src, size_t src_pos, size_t copy_size);
+ the used data in buffer. */
+void buffer_copy(buffer_t *dest, size_t dest_pos,
+ const buffer_t *src, size_t src_pos, size_t copy_size);
/* Append data to buffer from another. copy_size may be set to (size_t)-1 to
copy the rest of the used data in buffer. */
-size_t buffer_append_buf(buffer_t *dest, const buffer_t *src,
- size_t src_pos, size_t copy_size);
+void buffer_append_buf(buffer_t *dest, const buffer_t *src,
+ size_t src_pos, size_t copy_size);
-/* Returns pointer to specified position in buffer, or NULL if there's not
- enough space. WARNING: The returned address may become invalid if you add
- more data to buffer. */
+/* Returns pointer to specified position in buffer. WARNING: The returned
+ address may become invalid if you add more data to buffer. */
void *buffer_get_space_unsafe(buffer_t *buf, size_t pos, size_t size);
/* Increase the buffer usage by given size, and return a pointer to beginning
- of it, or NULL if there's not enough space in buffer. */
+ of it. */
void *buffer_append_space_unsafe(buffer_t *buf, size_t size);
/* Like buffer_get_data(), but don't return it as const. Returns NULL if the
Index: hex-binary.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/hex-binary.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- hex-binary.c 28 Jul 2004 15:21:28 -0000 1.7
+++ hex-binary.c 8 Oct 2004 17:51:48 -0000 1.8
@@ -61,10 +61,9 @@
else
return -1;
- if (buffer_append_c(dest, value) != 1)
- return 0;
+ buffer_append_c(dest, value);
data++;
}
- return 1;
+ return 0;
}
Index: hex-binary.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/hex-binary.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- hex-binary.h 28 Jul 2004 15:21:28 -0000 1.7
+++ hex-binary.h 8 Oct 2004 17:51:48 -0000 1.8
@@ -6,8 +6,7 @@
const char *binary_to_hex_ucase(const unsigned char *data, size_t size);
/* Convert hex to binary. data and dest may point to same value.
- Returns TRUE if successful. Returns 1 if all ok, 0 if dest buffer got full
- or -1 if data is invalid. */
+ Returns 0 if all ok, -1 if data is invalid. */
int hex_to_binary(const char *data, buffer_t *dest);
#endif
Index: ostream-crlf.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/ostream-crlf.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- ostream-crlf.c 25 Aug 2004 08:25:03 -0000 1.7
+++ ostream-crlf.c 8 Oct 2004 17:51:48 -0000 1.8
@@ -117,9 +117,8 @@
t_push();
iov_buf = buffer_create_dynamic(unsafe_data_stack_pool,
sizeof(struct const_iovec *) *
- IOVBUF_COUNT, (size_t)-1);
- diff_buf = buffer_create_dynamic(unsafe_data_stack_pool,
- IOVBUF_COUNT, (size_t)-1);
+ IOVBUF_COUNT);
+ diff_buf = buffer_create_dynamic(unsafe_data_stack_pool, IOVBUF_COUNT);
total = 0;
for (vec = 0; vec < iov_count; vec++) {
data = iov[vec].iov_base;
@@ -224,9 +223,8 @@
t_push();
iov_buf = buffer_create_dynamic(unsafe_data_stack_pool,
sizeof(struct const_iovec *) *
- IOVBUF_COUNT, (size_t)-1);
- diff_buf = buffer_create_dynamic(unsafe_data_stack_pool,
- IOVBUF_COUNT, (size_t)-1);
+ IOVBUF_COUNT);
+ diff_buf = buffer_create_dynamic(unsafe_data_stack_pool, IOVBUF_COUNT);
total = 0;
for (vec = 0; vec < iov_count; vec++) {
data = iov[vec].iov_base;
Index: str.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/str.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- str.c 17 Jun 2004 21:52:53 -0000 1.14
+++ str.c 8 Oct 2004 17:51:48 -0000 1.15
@@ -9,7 +9,7 @@
string_t *str_new(pool_t pool, size_t initial_size)
{
- return buffer_create_dynamic(pool, initial_size, (size_t)-1);
+ return buffer_create_dynamic(pool, initial_size);
}
string_t *t_str_new(size_t initial_size)
@@ -22,32 +22,20 @@
buffer_free(str);
}
-static int str_add_nul(string_t *str)
+static void str_add_nul(string_t *str)
{
size_t len;
len = str_len(str);
- if (buffer_write(str, len, "", 1) != 1) {
- /* no space - doesn't happen with our dynamically growing
- strings though, but make sure it's \0 terminated. */
- if (len == 0)
- return FALSE;
-
- len--;
- if (buffer_write(str, len, "", 1) != 1)
- i_panic("BUG in str_c()");
- }
+ buffer_write(str, len, "", 1);
/* remove the \0 - we don't want to keep it */
buffer_set_used_size(str, len);
- return TRUE;
}
const char *str_c(string_t *str)
{
- if (!str_add_nul(str))
- return "";
-
+ str_add_nul(str);
return buffer_get_data(str, NULL);
}
@@ -58,9 +46,7 @@
char *str_c_modifyable(string_t *str)
{
- if (!str_add_nul(str))
- return NULL;
-
+ str_add_nul(str);
return buffer_get_modifyable_data(str, NULL);
}
More information about the dovecot-cvs
mailing list