projects
/
ruby-eet.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Clear the stream after serializing it in Object#to_eet.
[ruby-eet.git]
/
ext
/
ext.c
diff --git
a/ext/ext.c
b/ext/ext.c
index e686444dc605b65fcaaa1b3405c86b803c82db0f..8ba3d5c16daf8d4a709e761f2263ae0cbae3600a 100644
(file)
--- a/
ext/ext.c
+++ b/
ext/ext.c
@@
-1,5
+1,5
@@
/*
/*
- * $Id: ext.c 6
6 2005-06-29 15:42:5
8Z tilman $
+ * $Id: ext.c 6
9 2005-07-08 22:35:0
8Z tilman $
*
* Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de)
*
*
* Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de)
*
@@
-467,7
+467,7
@@
stream_serialize (VALUE self)
static VALUE
chunk_init (VALUE self, VALUE tag, VALUE data)
{
static VALUE
chunk_init (VALUE self, VALUE tag, VALUE data)
{
-
unsigned long len
;
+
long tag_len, data_len, tmp
;
StringValue (tag);
StringValue (data);
StringValue (tag);
StringValue (data);
@@
-478,8
+478,11
@@
chunk_init (VALUE self, VALUE tag, VALUE data)
/* libeet uses a signed 32bit integer to store the
* chunk size, so make sure we don't overflow it
*/
/* libeet uses a signed 32bit integer to store the
* chunk size, so make sure we don't overflow it
*/
- len = RSTRING (tag)->len + 1 + RSTRING (data)->len;
- if (len < 0 || len >= 2147483647L)
+ tag_len = RSTRING (tag)->len;
+ data_len = RSTRING (data)->len;
+ tmp = tag_len + 1 + data_len;
+
+ if (tmp < tag_len || tmp < data_len || tmp < 1 || tmp >= 2147483647L)
rb_raise (rb_eArgError, "tag or data too long");
rb_ivar_set (self, id_tag, rb_str_dup_frozen (tag));
rb_raise (rb_eArgError, "tag or data too long");
rb_ivar_set (self, id_tag, rb_str_dup_frozen (tag));
@@
-497,11
+500,9
@@
chunk_serialize (VALUE self)
struct RString *tag, *data;
tmp = rb_ivar_get (self, id_tag);
struct RString *tag, *data;
tmp = rb_ivar_get (self, id_tag);
- StringValue (tmp);
tag = RSTRING (tmp);
tmp = rb_ivar_get (self, id_data);
tag = RSTRING (tmp);
tmp = rb_ivar_get (self, id_data);
- StringValue (tmp);
data = RSTRING (tmp);
buf_len = 9 + tag->len + data->len;
data = RSTRING (tmp);
buf_len = 9 + tag->len + data->len;
@@
-597,6
+598,9
@@
c_to_eet (VALUE self)
args[0] = name;
args[1] = rb_funcall (stream, id_serialize, 0);
args[0] = name;
args[1] = rb_funcall (stream, id_serialize, 0);
+
+ rb_ary_clear (stream); /* give the GC a hand... */
+
chunk = rb_class_new_instance (2, args, cChunk);
return rb_funcall (chunk, id_serialize, 0);
chunk = rb_class_new_instance (2, args, cChunk);
return rb_funcall (chunk, id_serialize, 0);