ox 1.2.6 → 1.2.7

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ox might be problematic. Click here for more details.

data/ext/ox/dump.c CHANGED
@@ -220,10 +220,10 @@ grow(Out out, size_t len) {
220
220
  char *buf;
221
221
 
222
222
  size *= 2;
223
- if (size < len + pos) {
223
+ if (size <= len * 2 + pos) {
224
224
  size += len;
225
225
  }
226
- if (0 == (buf = (char*)realloc(out->buf, size))) {
226
+ if (0 == (buf = (char*)realloc(out->buf, size + 10))) { // 1 extra for terminator character plus extra (paranoid)
227
227
  rb_raise(rb_eNoMemError, "Failed to create string. [%d:%s]\n", ENOSPC, strerror(ENOSPC));
228
228
  }
229
229
  out->buf = buf;
@@ -244,7 +244,7 @@ dump_start(Out out, Element e) {
244
244
  if (0 < e->id) { // i="id"
245
245
  size += 24; // over estimate, 19 digits
246
246
  }
247
- if (out->end - out->cur < (long)size) {
247
+ if (out->end - out->cur <= (long)size) {
248
248
  grow(out, size);
249
249
  }
250
250
  if (out->buf < out->cur) {
@@ -276,7 +276,7 @@ static void
276
276
  dump_end(Out out, Element e) {
277
277
  size_t size = e->indent + 5;
278
278
 
279
- if (out->end - out->cur < (long)size) {
279
+ if (out->end - out->cur <= (long)size) {
280
280
  grow(out, size);
281
281
  }
282
282
  fill_indent(out, e->indent);
@@ -289,7 +289,7 @@ dump_end(Out out, Element e) {
289
289
 
290
290
  inline static void
291
291
  dump_value(Out out, const char *value, size_t size) {
292
- if (out->end - out->cur < (long)size) {
292
+ if (out->end - out->cur <= (long)size) {
293
293
  grow(out, size);
294
294
  }
295
295
  if (6 < size) {
@@ -327,7 +327,7 @@ dump_num(Out out, VALUE obj) {
327
327
  } else {
328
328
  *b = '0';
329
329
  }
330
- if (out->end - out->cur < (long)(sizeof(buf) - (b - buf))) {
330
+ if (out->end - out->cur <= (long)(sizeof(buf) - (b - buf))) {
331
331
  grow(out, sizeof(buf) - (b - buf));
332
332
  }
333
333
  for (; '\0' != *b; b++) {
@@ -355,7 +355,7 @@ dump_time_thin(Out out, VALUE obj) {
355
355
  }
356
356
  b++;
357
357
  size = sizeof(buf) - (b - buf) - 1;
358
- if (out->end - out->cur < size) {
358
+ if (out->end - out->cur <= size) {
359
359
  grow(out, size);
360
360
  }
361
361
  memcpy(out->cur, b, size);
@@ -370,7 +370,7 @@ dump_time_xsd(Out out, VALUE obj) {
370
370
  int tzhour, tzmin;
371
371
  char tzsign = '+';
372
372
 
373
- if (out->end - out->cur < 33) {
373
+ if (out->end - out->cur <= 33) {
374
374
  grow(out, 33);
375
375
  }
376
376
  // 2010-07-09T10:47:45.895826+09:00
@@ -800,7 +800,7 @@ dump_gen_element(VALUE obj, unsigned int depth, Out out) {
800
800
  indent = depth * out->indent;
801
801
  }
802
802
  size = indent + 4 + nlen;
803
- if (out->end - out->cur < (long)size) {
803
+ if (out->end - out->cur <= (long)size) {
804
804
  grow(out, size);
805
805
  }
806
806
  fill_indent(out, indent);
@@ -814,7 +814,7 @@ dump_gen_element(VALUE obj, unsigned int depth, Out out) {
814
814
 
815
815
  *out->cur++ = '>';
816
816
  do_indent = dump_gen_nodes(nodes, depth, out);
817
- if (out->end - out->cur < (long)size) {
817
+ if (out->end - out->cur <= (long)size) {
818
818
  grow(out, size);
819
819
  }
820
820
  if (do_indent) {
@@ -867,7 +867,7 @@ dump_gen_attr(VALUE key, VALUE value, Out out) {
867
867
  size_t klen = strlen(ks);
868
868
  size_t size = 4 + klen + RSTRING_LEN(value);
869
869
 
870
- if (out->end - out->cur < (long)size) {
870
+ if (out->end - out->cur <= (long)size) {
871
871
  grow(out, size);
872
872
  }
873
873
  *out->cur++ = ' ';
@@ -903,7 +903,7 @@ dump_gen_val_node(VALUE obj, unsigned int depth,
903
903
  indent = depth * out->indent;
904
904
  }
905
905
  size = indent + plen + slen + vlen;
906
- if (out->end - out->cur < (long)size) {
906
+ if (out->end - out->cur <= (long)size) {
907
907
  grow(out, size);
908
908
  }
909
909
  fill_indent(out, indent);
@@ -945,7 +945,6 @@ write_obj_to_str(VALUE obj, Options copts) {
945
945
  struct _Out out;
946
946
 
947
947
  dump_obj_to_xml(obj, copts, &out);
948
-
949
948
  return out.buf;
950
949
  }
951
950
 
data/ext/ox/obj_load.c CHANGED
@@ -107,7 +107,6 @@ resolve_classname(VALUE mod, const char *class_name, Effort effort) {
107
107
  }
108
108
  break;
109
109
  case AutoEffort:
110
- //printf("*** auto %s\n", class_name);
111
110
  if (rb_const_defined_at(mod, ci)) {
112
111
  clas = rb_const_get_at(mod, ci);
113
112
  } else {
data/lib/ox/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Ox
3
3
  # Current version of the module.
4
- VERSION = '1.2.6'
4
+ VERSION = '1.2.7'
5
5
  end
data/test/big.rb ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby -wW1
2
+
3
+ $: << '../lib'
4
+ $: << '../ext'
5
+
6
+ if __FILE__ == $0
7
+ while (i = ARGV.index('-I'))
8
+ x,path = ARGV.slice!(i, 2)
9
+ $: << path
10
+ end
11
+ end
12
+
13
+ require 'ox'
14
+
15
+ def dump(cnt = 10000)
16
+ h = { }
17
+ cnt.times do |i|
18
+ h[i] = [i * 2, "this is #{i}"]
19
+ end
20
+ xml = Ox.dump(h)
21
+ puts "size: #{xml.size}"
22
+ end
23
+
24
+ dump(200000)
data/test/bug3.rb ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby -wW1
2
+
3
+ $: << '../lib'
4
+ $: << '../ext'
5
+
6
+ if __FILE__ == $0
7
+ if (i = ARGV.index('-I'))
8
+ x,path = ARGV.slice!(i, 2)
9
+ $: << path
10
+ end
11
+ end
12
+
13
+ require 'ox'
14
+
15
+ def dump(cnt = 100000)
16
+ cnt.times do |i|
17
+ xml = Ox.dump([:inc, 1])
18
+ #puts xml
19
+
20
+ end
21
+ end
22
+
23
+ dump()
metadata CHANGED
@@ -1,8 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ox
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 1.2.6
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 2
8
+ - 7
9
+ version: 1.2.7
6
10
  platform: ruby
7
11
  authors:
8
12
  - Peter Ohler
@@ -10,7 +14,7 @@ autorequire:
10
14
  bindir: bin
11
15
  cert_chain: []
12
16
 
13
- date: 2011-08-18 00:00:00 +09:00
17
+ date: 2011-08-19 00:00:00 +09:00
14
18
  default_executable:
15
19
  dependencies: []
16
20
 
@@ -47,8 +51,10 @@ files:
47
51
  - ext/ox/obj_load.c
48
52
  - ext/ox/ox.c
49
53
  - ext/ox/parse.c
54
+ - test/big.rb
50
55
  - test/bug1.rb
51
56
  - test/bug2.rb
57
+ - test/bug3.rb
52
58
  - test/cache16_test.rb
53
59
  - test/cache8_test.rb
54
60
  - test/cache_test.rb
@@ -94,17 +100,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
94
100
  requirements:
95
101
  - - ">="
96
102
  - !ruby/object:Gem::Version
103
+ segments:
104
+ - 0
97
105
  version: "0"
98
106
  required_rubygems_version: !ruby/object:Gem::Requirement
99
107
  none: false
100
108
  requirements:
101
109
  - - ">="
102
110
  - !ruby/object:Gem::Version
111
+ segments:
112
+ - 0
103
113
  version: "0"
104
114
  requirements: []
105
115
 
106
116
  rubyforge_project: ox
107
- rubygems_version: 1.6.2
117
+ rubygems_version: 1.3.7
108
118
  signing_key:
109
119
  specification_version: 3
110
120
  summary: A fast XML parser and object serializer.