z85 0.8 → 0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/z85/z85.c +4 -19
- data/lib/z85/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b8a8f710b44f09a0f49dcd06e762772a7be52afe545c9704c9bfc3b8fb18686
|
4
|
+
data.tar.gz: 0ca0ddb2f4a4acb520be1ff60e5ccb1e2c570db10ec7c1cc2dc94635b68c05ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 288828a461c5de1c20ae44c03b275dfa5c21264517c397be2bb03bf7da5c4bfd59d4d882afe5d3c258f8279836513a1508b712d6225e981813f690fcf8fa76ea
|
7
|
+
data.tar.gz: 782da75afcaeaca47cddc7dfd85893b96ca8ddec4d9f32721e39027803f236d754a80d88c8f3114e9787df70a61f3d12bd6c3cd582a2d7f9bbdb8ceb1f8558df
|
data/ext/z85/z85.c
CHANGED
@@ -60,28 +60,13 @@ static byte decoder[96] = {
|
|
60
60
|
0x21, 0x22, 0x23, 0x4F, 0x00, 0x50, 0x00, 0x00
|
61
61
|
};
|
62
62
|
|
63
|
-
static void* z85_malloc(size_t size)
|
64
|
-
{
|
65
|
-
void* ptr = malloc(size);
|
66
|
-
|
67
|
-
/*
|
68
|
-
malloc(0) is implementation-defined and could return NULL, so if ptr is
|
69
|
-
NULL, we need to check size too before raising. Note that free(NULL) is
|
70
|
-
valid (it does nothing).
|
71
|
-
*/
|
72
|
-
if (!ptr && size)
|
73
|
-
rb_raise(rb_eNoMemError, "Out of memory");
|
74
|
-
|
75
|
-
return ptr;
|
76
|
-
}
|
77
|
-
|
78
63
|
static VALUE z85_encode(VALUE _mod, VALUE string)
|
79
64
|
{
|
80
65
|
byte* data = (byte*) StringValuePtr(string);
|
81
66
|
long size = RSTRING_LEN(string);
|
82
67
|
|
83
68
|
size_t encoded_len = size * 5 / 4;
|
84
|
-
char* encoded =
|
69
|
+
char* encoded = xmalloc(encoded_len + 1);
|
85
70
|
uint char_nbr = 0;
|
86
71
|
uint byte_nbr = 0;
|
87
72
|
uint32_t value = 0;
|
@@ -100,7 +85,7 @@ static VALUE z85_encode(VALUE _mod, VALUE string)
|
|
100
85
|
encoded[char_nbr] = 0;
|
101
86
|
|
102
87
|
VALUE out = rb_usascii_str_new_cstr(encoded);
|
103
|
-
|
88
|
+
xfree(encoded);
|
104
89
|
return out;
|
105
90
|
}
|
106
91
|
|
@@ -112,7 +97,7 @@ static VALUE z85_decode(VALUE _mod, VALUE rstring)
|
|
112
97
|
strlen--; /* It is padded, ignore the counter */
|
113
98
|
|
114
99
|
size_t decoded_size = strlen * 4 / 5;
|
115
|
-
byte* decoded =
|
100
|
+
byte* decoded = xmalloc(decoded_size);
|
116
101
|
|
117
102
|
uint byte_nbr = 0;
|
118
103
|
uint char_nbr = 0;
|
@@ -130,7 +115,7 @@ static VALUE z85_decode(VALUE _mod, VALUE rstring)
|
|
130
115
|
}
|
131
116
|
|
132
117
|
VALUE out = rb_str_new((const char*) decoded, decoded_size);
|
133
|
-
|
118
|
+
xfree(decoded);
|
134
119
|
return out;
|
135
120
|
}
|
136
121
|
|
data/lib/z85/version.rb
CHANGED