summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--utils/bencoding.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/utils/bencoding.c b/utils/bencoding.c
index ad6ded0..c12369b 100644
--- a/utils/bencoding.c
+++ b/utils/bencoding.c
@@ -24,50 +24,55 @@ int main (int argc, char ** argv) {
struct bencoding * bencoding = bdecode(in, size, 0);
if (argv[1][0] == 'd') {
len = b2json_length(bencoding);
- char out[len+1];
+ char * out = malloc(len+1);
char * end = b2json(out, bencoding);
*end = '\0';
puts(out);
if (end - out != len)
error_at_line(4, 0, __FILE__, __LINE__, "b2json wrote %td instead of %d bytes.", end-out, len);
fprintf(stderr, "len: %d\n", len);
+ free(out);
}
if (argv[1][0] == 'p') {
len = b2json_length(bpath(bencoding, argv[2]));
- char out[len+1];
+ char * out = malloc(len+1);
char * end = b2json(out, bpath(bencoding, argv[2]));
*end = '\0';
puts(out);
if (end - out != len)
error_at_line(4, 0, __FILE__, __LINE__, "b2json wrote %td instead of %d bytes.", end-out, len);
fprintf(stderr, "len: %d\n", len);
+ free(out);
}
if (argv[1][0] == 'v') {
len = b2json_length(bval(bencoding, bstrs(argv[2])));
- char out[len+1];
+ char * out = malloc(len+1);
char * end = b2json(out, bval(bencoding, bstrs(argv[2])));
*end = '\0';
puts(out);
if (end - out != len)
error_at_line(4, 0, __FILE__, __LINE__, "b2json wrote %td instead of %d bytes.", end-out, len);
fprintf(stderr, "len: %d\n", len);
+ free(out);
}
if (argv[1][0] == 'f') {
bforeach (bencoding, value) {
len = b2json_length(value->key);
- char out[len+1];
+ char * out = malloc(len+1);
char * end = b2json(out, value->key);
*end = '\0';
if (end - out != len)
error_at_line(4, 0, __FILE__, __LINE__, "b2json wrote %td instead of %d bytes.", end-out, len);
printf("key(%d): %s\n", len, out);
len = b2json_length(value);
- char out2[len+1];
+ char * out2 = malloc(len+1);
end = b2json(out2, value);
*end = '\0';
if (end - out2 != len)
error_at_line(4, 0, __FILE__, __LINE__, "b2json wrote %td instead of %d bytes.", end-out2, len);
printf("value(%d): %s\n", len, out2);
+ free(out);
+ free(out2);
}
}
if (argv[1][0] == 'i') {
@@ -80,13 +85,14 @@ int main (int argc, char ** argv) {
elem->child = NULL;
free_bencoding(elem);
len = b2json_length(bencoding);
- char out[len+1];
+ char * out = malloc(len+1);
char * end = b2json(out, bencoding);
*end = '\0';
puts(out);
if (end - out != len)
error_at_line(4, 0, __FILE__, __LINE__, "b2json wrote %td instead of %d bytes.", end-out, len);
fprintf(stderr, "len: %d\n", len);
+ free(out);
}
if (argv[1][0] == 'c') {
struct bencoding * elem = bdecode(argv[2], -2, 0);
@@ -105,10 +111,11 @@ int main (int argc, char ** argv) {
}
if (argv[1][0] == 'e') {
int len = bencode_length(bencoding);
- char bencoded[len+1];
+ char * bencoded = malloc(len+1);
bencoded[len] = '\0';
bencode(bencoded, bencoding);
puts(bencoded);
+ free(bencoded);
}
free_bencoding(bencoding);
free(in);