ox 2.14.13 → 2.14.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f9742d803f0730d6e9724d0f08809ec291b474beae8e966cf3b9ab3c95e165fa
4
- data.tar.gz: 102f6dc50ee242f5a7cbb4e8395aa4004d826679b5b02f0e9734d3e8d206d7ec
3
+ metadata.gz: 673ab7acb7140b9e29888304ab457c13558c2f774dbd4364d1899349b6f68210
4
+ data.tar.gz: 7eebc70a320a14359ba774c22700764916fd1b3399b1e3bf9e555e43f1643a5b
5
5
  SHA512:
6
- metadata.gz: 754fe3197d3944d4b398ba0334d62bc45d066448885e9a47ac8216c0a292203f273c4f0ab764a3ec4e5e49ebc472282ac89821aa0f03929491c60c659494e02b
7
- data.tar.gz: 31f01b2ca8b2440511c9eda13fe590937bfd266173d83befcc81e228c0e8516545a29369755f1575c2e8bdb11aac791e463a397035fafed8e13848a23c8fb255
6
+ metadata.gz: 6019b22adf12fe6390280281705552a171c62e5863f74281f658ceb1743401f429b9324716bbb7eaa96a79ea06f1d8a1f205c8706fb00685c3fe45bdeed00f9d
7
+ data.tar.gz: f64209e6be760b0f6a1606c7ecbcbd51769ddd70bc908b21b1b935ab99ce5ba9f7049015171f7b9fd6ec2801d20823b40b5546a80d1736ce84ddfa7a2acb7278
data/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  All changes to the Ox gem are documented here. Releases follow semantic versioning.
4
4
 
5
+ ## [2.14.15] - 2023-04-10
6
+
7
+ ### Fixed
8
+
9
+ - Fixed free on moved pointer.
10
+
11
+ ## [2.14.14] - 2023-01-26
12
+
13
+ ### Fixed
14
+
15
+ - Change free to xfree on ruby alloced memory.
16
+
5
17
  ## [2.14.13] - 2023-01-16
6
18
 
7
19
  ### Fixed
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Ox gem
2
2
  A fast XML parser and Object marshaller as a Ruby gem.
3
3
 
4
- [![Build Status](https://img.shields.io/github/workflow/status/ohler55/ox/CI?logo=github)](https://github.com/ohler55/ox/actions/workflows/CI.yml)
4
+ [![CI](https://github.com/ohler55/ox/actions/workflows/CI.yml/badge.svg)](https://github.com/ohler55/ox/actions/workflows/CI.yml)
5
5
 
6
6
  ## Installation
7
7
  gem install ox
data/ext/ox/attr.h CHANGED
@@ -6,77 +6,71 @@
6
6
  #ifndef OX_ATTR_H
7
7
  #define OX_ATTR_H
8
8
 
9
- #include "ox.h"
9
+ #include <ruby.h>
10
10
 
11
- #define ATTR_STACK_INC 8
11
+ #define ATTR_STACK_INC 8
12
12
 
13
13
  typedef struct _attr {
14
- const char *name;
15
- const char *value;
14
+ const char *name;
15
+ const char *value;
16
16
  } *Attr;
17
17
 
18
18
  typedef struct _attrStack {
19
- struct _attr base[ATTR_STACK_INC];
20
- Attr head; /* current stack */
21
- Attr end; /* stack end */
22
- Attr tail; /* pointer to one past last element name on stack */
19
+ struct _attr base[ATTR_STACK_INC];
20
+ Attr head; /* current stack */
21
+ Attr end; /* stack end */
22
+ Attr tail; /* pointer to one past last element name on stack */
23
23
  } *AttrStack;
24
24
 
25
- inline static void
26
- attr_stack_init(AttrStack stack) {
27
- stack->head = stack->base;
28
- stack->end = stack->base + sizeof(stack->base) / sizeof(struct _attr);
29
- stack->tail = stack->head;
25
+ inline static void attr_stack_init(AttrStack stack) {
26
+ stack->head = stack->base;
27
+ stack->end = stack->base + sizeof(stack->base) / sizeof(struct _attr);
28
+ stack->tail = stack->head;
30
29
  stack->head->name = 0;
31
30
  }
32
31
 
33
- inline static int
34
- attr_stack_empty(AttrStack stack) {
32
+ inline static int attr_stack_empty(AttrStack stack) {
35
33
  return (stack->head == stack->tail);
36
34
  }
37
35
 
38
- inline static void
39
- attr_stack_cleanup(AttrStack stack) {
36
+ inline static void attr_stack_cleanup(AttrStack stack) {
40
37
  if (stack->base != stack->head) {
41
38
  xfree(stack->head);
42
- stack->head = stack->base;
39
+ stack->head = stack->base;
43
40
  }
44
41
  }
45
42
 
46
- inline static void
47
- attr_stack_push(AttrStack stack, const char *name, const char *value) {
43
+ inline static void attr_stack_push(AttrStack stack, const char *name, const char *value) {
48
44
  if (stack->end <= stack->tail + 1) {
49
- size_t len = stack->end - stack->head;
50
- size_t toff = stack->tail - stack->head;
45
+ size_t len = stack->end - stack->head;
46
+ size_t toff = stack->tail - stack->head;
51
47
 
52
- if (stack->base == stack->head) {
53
- stack->head = ALLOC_N(struct _attr, len + ATTR_STACK_INC);
54
- memcpy(stack->head, stack->base, sizeof(struct _attr) * len);
55
- } else {
56
- REALLOC_N(stack->head, struct _attr, len + ATTR_STACK_INC);
57
- }
58
- stack->tail = stack->head + toff;
59
- stack->end = stack->head + len + ATTR_STACK_INC;
48
+ if (stack->base == stack->head) {
49
+ stack->head = ALLOC_N(struct _attr, len + ATTR_STACK_INC);
50
+ memcpy(stack->head, stack->base, sizeof(struct _attr) * len);
51
+ } else {
52
+ REALLOC_N(stack->head, struct _attr, len + ATTR_STACK_INC);
53
+ }
54
+ stack->tail = stack->head + toff;
55
+ stack->end = stack->head + len + ATTR_STACK_INC;
60
56
  }
61
- stack->tail->name = name;
57
+ stack->tail->name = name;
62
58
  stack->tail->value = value;
63
59
  stack->tail++;
64
- stack->tail->name = 0; // terminate
60
+ stack->tail->name = 0; // terminate
65
61
  }
66
62
 
67
- inline static Attr
68
- attr_stack_peek(AttrStack stack) {
63
+ inline static Attr attr_stack_peek(AttrStack stack) {
69
64
  if (stack->head < stack->tail) {
70
- return stack->tail - 1;
65
+ return stack->tail - 1;
71
66
  }
72
67
  return 0;
73
68
  }
74
69
 
75
- inline static Attr
76
- attr_stack_pop(AttrStack stack) {
70
+ inline static Attr attr_stack_pop(AttrStack stack) {
77
71
  if (stack->head < stack->tail) {
78
- stack->tail--;
79
- return stack->tail;
72
+ stack->tail--;
73
+ return stack->tail;
80
74
  }
81
75
  return 0;
82
76
  }
data/ext/ox/base64.c CHANGED
@@ -3,15 +3,15 @@
3
3
  * All rights reserved.
4
4
  */
5
5
 
6
- #include <stdlib.h>
7
- #include <stdio.h>
8
-
9
6
  #include "base64.h"
10
7
 
11
- static char digits[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
8
+ #include <stdio.h>
9
+ #include <stdlib.h>
10
+
11
+ static char digits[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
12
12
 
13
13
  /* invalid or terminating characters are set to 'X' or \x58 */
14
- static uchar s_digits[256] = "\
14
+ static uchar s_digits[256] = "\
15
15
  \x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\
16
16
  \x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\
17
17
  \x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x3E\x58\x58\x58\x3F\
@@ -29,46 +29,45 @@ static uchar s_digits[256] = "\
29
29
  \x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\
30
30
  \x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58";
31
31
 
32
- void
33
- to_base64(const uchar *src, int len, char *b64) {
34
- const uchar *end3;
35
- int len3 = len % 3;
36
- uchar b1, b2, b3;
37
-
32
+ void to_base64(const uchar *src, int len, char *b64) {
33
+ const uchar *end3;
34
+ int len3 = len % 3;
35
+ uchar b1, b2, b3;
36
+
38
37
  end3 = src + (len - len3);
39
38
  while (src < end3) {
40
- b1 = *src++;
41
- b2 = *src++;
42
- b3 = *src++;
43
- *b64++ = digits[(uchar)(b1 >> 2)];
44
- *b64++ = digits[(uchar)(((b1 & 0x03) << 4) | (b2 >> 4))];
45
- *b64++ = digits[(uchar)(((b2 & 0x0F) << 2) | (b3 >> 6))];
46
- *b64++ = digits[(uchar)(b3 & 0x3F)];
39
+ b1 = *src++;
40
+ b2 = *src++;
41
+ b3 = *src++;
42
+ *b64++ = digits[(uchar)(b1 >> 2)];
43
+ *b64++ = digits[(uchar)(((b1 & 0x03) << 4) | (b2 >> 4))];
44
+ *b64++ = digits[(uchar)(((b2 & 0x0F) << 2) | (b3 >> 6))];
45
+ *b64++ = digits[(uchar)(b3 & 0x3F)];
47
46
  }
48
47
  if (1 == len3) {
49
- b1 = *src++;
50
- *b64++ = digits[b1 >> 2];
51
- *b64++ = digits[(b1 & 0x03) << 4];
52
- *b64++ = '=';
53
- *b64++ = '=';
48
+ b1 = *src++;
49
+ *b64++ = digits[b1 >> 2];
50
+ *b64++ = digits[(b1 & 0x03) << 4];
51
+ *b64++ = '=';
52
+ *b64++ = '=';
54
53
  } else if (2 == len3) {
55
- b1 = *src++;
56
- b2 = *src++;
57
- *b64++ = digits[b1 >> 2];
58
- *b64++ = digits[((b1 & 0x03) << 4) | (b2 >> 4)];
59
- *b64++ = digits[(b2 & 0x0F) << 2];
60
- *b64++ = '=';
54
+ b1 = *src++;
55
+ b2 = *src++;
56
+ *b64++ = digits[b1 >> 2];
57
+ *b64++ = digits[((b1 & 0x03) << 4) | (b2 >> 4)];
58
+ *b64++ = digits[(b2 & 0x0F) << 2];
59
+ *b64++ = '=';
61
60
  }
62
61
  *b64 = '\0';
63
62
  }
64
63
 
65
- unsigned long
66
- b64_orig_size(const char *text) {
67
- const char *start = text;
68
- unsigned long size = 0;
64
+ unsigned long b64_orig_size(const char *text) {
65
+ const char *start = text;
66
+ unsigned long size = 0;
69
67
 
70
68
  if ('\0' != *text) {
71
- for (; 0 != *text; text++) { }
69
+ for (; 0 != *text; text++) {
70
+ }
72
71
  size = (text - start) * 3 / 4;
73
72
  text--;
74
73
  if ('=' == *text) {
@@ -82,17 +81,24 @@ b64_orig_size(const char *text) {
82
81
  return size;
83
82
  }
84
83
 
85
- void
86
- from_base64(const char *b64, uchar *str) {
87
- uchar b0, b1, b2, b3;
88
-
84
+ void from_base64(const char *b64, uchar *str) {
85
+ uchar b0, b1, b2, b3;
86
+
89
87
  while (1) {
90
- if ('X' == (b0 = s_digits[(uchar)*b64++])) { break; }
91
- if ('X' == (b1 = s_digits[(uchar)*b64++])) { break; }
88
+ if ('X' == (b0 = s_digits[(uchar)*b64++])) {
89
+ break;
90
+ }
91
+ if ('X' == (b1 = s_digits[(uchar)*b64++])) {
92
+ break;
93
+ }
92
94
  *str++ = (b0 << 2) | ((b1 >> 4) & 0x03);
93
- if ('X' == (b2 = s_digits[(uchar)*b64++])) { break; }
95
+ if ('X' == (b2 = s_digits[(uchar)*b64++])) {
96
+ break;
97
+ }
94
98
  *str++ = (b1 << 4) | ((b2 >> 2) & 0x0F);
95
- if ('X' == (b3 = s_digits[(uchar)*b64++])) { break; }
99
+ if ('X' == (b3 = s_digits[(uchar)*b64++])) {
100
+ break;
101
+ }
96
102
  *str++ = (b2 << 6) | b3;
97
103
  }
98
104
  *str = '\0';
data/ext/ox/base64.h CHANGED
@@ -6,13 +6,13 @@
6
6
  #ifndef BASE64_H
7
7
  #define BASE64_H
8
8
 
9
- typedef unsigned char uchar;
9
+ typedef unsigned char uchar;
10
10
 
11
11
  #define b64_size(len) ((len + 2) / 3 * 4)
12
12
 
13
- extern unsigned long b64_orig_size(const char *text);
13
+ extern unsigned long b64_orig_size(const char *text);
14
14
 
15
- extern void to_base64(const uchar *src, int len, char *b64);
16
- extern void from_base64(const char *b64, uchar *str);
15
+ extern void to_base64(const uchar *src, int len, char *b64);
16
+ extern void from_base64(const char *b64, uchar *str);
17
17
 
18
18
  #endif /* BASE64_H */
data/ext/ox/buf.h CHANGED
@@ -31,137 +31,131 @@
31
31
  #ifndef OX_BUF_H
32
32
  #define OX_BUF_H
33
33
 
34
+ #include <ruby.h>
34
35
  #include <stdbool.h>
35
36
  #include <unistd.h>
36
37
 
37
38
  typedef struct _buf {
38
- char *head;
39
- char *end;
40
- char *tail;
41
- int fd;
42
- bool err;
43
- char base[16384];
39
+ char *head;
40
+ char *end;
41
+ char *tail;
42
+ int fd;
43
+ bool err;
44
+ char base[16384];
44
45
  } *Buf;
45
46
 
46
- inline static void
47
- buf_init(Buf buf, int fd, long initial_size) {
47
+ inline static void buf_init(Buf buf, int fd, long initial_size) {
48
48
  if (sizeof(buf->base) < (size_t)initial_size) {
49
- buf->head = ALLOC_N(char, initial_size);
50
- buf->end = buf->head + initial_size - 1;
49
+ buf->head = ALLOC_N(char, initial_size);
50
+ buf->end = buf->head + initial_size - 1;
51
51
  } else {
52
- buf->head = buf->base;
53
- buf->end = buf->base + sizeof(buf->base) - 1;
52
+ buf->head = buf->base;
53
+ buf->end = buf->base + sizeof(buf->base) - 1;
54
54
  }
55
55
  buf->tail = buf->head;
56
- buf->fd = fd;
57
- buf->err = false;
56
+ buf->fd = fd;
57
+ buf->err = false;
58
58
  }
59
59
 
60
- inline static void
61
- buf_reset(Buf buf) {
60
+ inline static void buf_reset(Buf buf) {
62
61
  buf->head = buf->base;
63
62
  buf->tail = buf->head;
64
63
  }
65
64
 
66
- inline static void
67
- buf_cleanup(Buf buf) {
65
+ inline static void buf_cleanup(Buf buf) {
68
66
  if (buf->base != buf->head) {
69
67
  free(buf->head);
70
68
  }
71
69
  }
72
70
 
73
- inline static size_t
74
- buf_len(Buf buf) {
71
+ inline static size_t buf_len(Buf buf) {
75
72
  return buf->tail - buf->head;
76
73
  }
77
74
 
78
- inline static void
79
- buf_append_string(Buf buf, const char *s, size_t slen) {
75
+ inline static void buf_append_string(Buf buf, const char *s, size_t slen) {
80
76
  if (buf->err) {
81
- return;
77
+ return;
82
78
  }
83
79
  if (buf->end <= buf->tail + slen) {
84
- if (0 != buf->fd) {
85
- size_t len = buf->tail - buf->head;
86
-
87
- if (len != (size_t)write(buf->fd, buf->head, len)) {
88
- buf->err = true;
89
- return;
90
- }
91
- buf->tail = buf->head;
92
- if (sizeof(buf->base) <= slen) {
93
- if (slen != (size_t)write(buf->fd, s, slen)) {
94
- buf->err = true;
95
- return;
96
- }
97
- return;
98
- }
99
- } else {
100
- size_t len = buf->end - buf->head;
101
- size_t toff = buf->tail - buf->head;
102
- size_t new_len = len + slen + len / 2;
103
-
104
- if (buf->base == buf->head) {
105
- buf->head = ALLOC_N(char, new_len);
106
- memcpy(buf->head, buf->base, len);
107
- } else {
108
- REALLOC_N(buf->head, char, new_len);
109
- }
110
- buf->tail = buf->head + toff;
111
- buf->end = buf->head + new_len - 2;
112
- }
80
+ if (0 != buf->fd) {
81
+ size_t len = buf->tail - buf->head;
82
+
83
+ if (len != (size_t)write(buf->fd, buf->head, len)) {
84
+ buf->err = true;
85
+ return;
86
+ }
87
+ buf->tail = buf->head;
88
+ if (sizeof(buf->base) <= slen) {
89
+ if (slen != (size_t)write(buf->fd, s, slen)) {
90
+ buf->err = true;
91
+ return;
92
+ }
93
+ return;
94
+ }
95
+ } else {
96
+ size_t len = buf->end - buf->head;
97
+ size_t toff = buf->tail - buf->head;
98
+ size_t new_len = len + slen + len / 2;
99
+
100
+ if (buf->base == buf->head) {
101
+ buf->head = ALLOC_N(char, new_len);
102
+ memcpy(buf->head, buf->base, len);
103
+ } else {
104
+ REALLOC_N(buf->head, char, new_len);
105
+ }
106
+ buf->tail = buf->head + toff;
107
+ buf->end = buf->head + new_len - 2;
108
+ }
113
109
  }
114
110
  if (0 < slen) {
115
- memcpy(buf->tail, s, slen);
111
+ memcpy(buf->tail, s, slen);
116
112
  }
117
113
  buf->tail += slen;
118
114
  }
119
115
 
120
- inline static void
121
- buf_append(Buf buf, char c) {
116
+ inline static void buf_append(Buf buf, char c) {
122
117
  if (buf->err) {
123
- return;
118
+ return;
124
119
  }
125
120
  if (buf->end <= buf->tail) {
126
- if (0 != buf->fd) {
127
- size_t len = buf->tail - buf->head;
128
-
129
- if (len != (size_t)write(buf->fd, buf->head, len)) {
130
- buf->err = true;
131
- }
132
- buf->tail = buf->head;
133
- } else {
134
- size_t len = buf->end - buf->head;
135
- size_t toff = buf->tail - buf->head;
136
- size_t new_len = len + len / 2;
137
-
138
- if (buf->base == buf->head) {
139
- buf->head = ALLOC_N(char, new_len);
140
- memcpy(buf->head, buf->base, len);
141
- } else {
142
- REALLOC_N(buf->head, char, new_len);
143
- }
144
- buf->tail = buf->head + toff;
145
- buf->end = buf->head + new_len - 2;
146
- }
121
+ if (0 != buf->fd) {
122
+ size_t len = buf->tail - buf->head;
123
+
124
+ if (len != (size_t)write(buf->fd, buf->head, len)) {
125
+ buf->err = true;
126
+ }
127
+ buf->tail = buf->head;
128
+ } else {
129
+ size_t len = buf->end - buf->head;
130
+ size_t toff = buf->tail - buf->head;
131
+ size_t new_len = len + len / 2;
132
+
133
+ if (buf->base == buf->head) {
134
+ buf->head = ALLOC_N(char, new_len);
135
+ memcpy(buf->head, buf->base, len);
136
+ } else {
137
+ REALLOC_N(buf->head, char, new_len);
138
+ }
139
+ buf->tail = buf->head + toff;
140
+ buf->end = buf->head + new_len - 2;
141
+ }
147
142
  }
148
143
  *buf->tail++ = c;
149
144
  //*buf->tail = '\0'; // for debugging
150
145
  }
151
146
 
152
- inline static void
153
- buf_finish(Buf buf) {
147
+ inline static void buf_finish(Buf buf) {
154
148
  if (buf->err) {
155
- return;
149
+ return;
156
150
  }
157
151
  if (0 != buf->fd) {
158
- size_t len = buf->tail - buf->head;
152
+ size_t len = buf->tail - buf->head;
159
153
 
160
- if (0 < len && len != (size_t)write(buf->fd, buf->head, len)) {
161
- buf->err = true;
162
- }
163
- fsync(buf->fd);
164
- buf->tail = buf->head;
154
+ if (0 < len && len != (size_t)write(buf->fd, buf->head, len)) {
155
+ buf->err = true;
156
+ }
157
+ fsync(buf->fd);
158
+ buf->tail = buf->head;
165
159
  }
166
160
  }
167
161