Merge pull request #278 from PhenomRetroShare/Fix_bencode.c_CompilationForC

Fix compilation of bencode.c for C compilator.
This commit is contained in:
Cyril Soler 2016-02-14 13:35:32 -05:00
commit 44882b941c

View File

@ -20,7 +20,6 @@
*/
#include <stdio.h>
#include <iostream>
#include <stdlib.h> /* malloc() realloc() free() strtoll() */
#include <string.h> /* memset() */
#include "util/bdstring.h"
@ -115,8 +114,10 @@ static char *_be_decode_str(const char **data, long long *data_len)
if(_ret == NULL)
{
std::cerr << "(EE) " << __PRETTY_FUNCTION__ << ": ERROR. cannot allocate memory for " << len+1+sizeof(sllen) << " bytes." << std::endl;
return NULL;
fprintf(stderr, "(EE) bencode::_be_decode_str(): "
"ERROR. cannot allocate memory for %lu bytes.\n"
, len+1+sizeof(sllen) );
return ret;
}
memcpy(_ret, &sllen, sizeof(sllen));
@ -504,17 +505,19 @@ be_node *be_create_str(const char *str)
{
/* must */
be_node *n = be_alloc(BE_STR);
be_node *n = NULL;
int len = strlen(str);
long long int sllen = len;
char *_ret = (char *) malloc(sizeof(sllen) + len + 1);
if(_ret == NULL)
{
std::cerr << "(EE) " << __PRETTY_FUNCTION__ << ": ERROR. cannot allocate memory for " << len+1+sizeof(sllen) << " bytes." << std::endl;
return NULL;
fprintf(stderr, "(EE) bencode::be_create_str(): "
"ERROR. cannot allocate memory for %lu bytes.\n"
, len+1+sizeof(sllen) );
return n;
}
char *ret = NULL;
n = be_alloc(BE_STR);
memcpy(_ret, &sllen, sizeof(sllen));
ret = _ret + sizeof(sllen);
@ -530,16 +533,18 @@ be_node *be_create_str_wlen(const char *str, int len) /* not including \0 */
{
/* must */
be_node *n = be_alloc(BE_STR);
be_node *n = NULL;
long long int sllen = len;
char *_ret = (char *) malloc(sizeof(sllen) + len + 1);
if(_ret == NULL)
{
std::cerr << "(EE) " << __PRETTY_FUNCTION__ << ": ERROR. cannot allocate memory for " << len+1+sizeof(sllen) << " bytes." << std::endl;
return NULL;
fprintf(stderr, "(EE) bencode::be_create_str_wlen(): "
"ERROR. cannot allocate memory for %lu bytes.\n"
, len+1+sizeof(sllen) );
return n;
}
char *ret = NULL;
n = be_alloc(BE_STR);
memcpy(_ret, &sllen, sizeof(sllen));
ret = _ret + sizeof(sllen);
@ -570,7 +575,8 @@ int be_add_keypair(be_node *dict, const char *str, be_node *node)
}
// get to end of dict.
for(i = 0; dict->val.d[i].val; i++);
for(i = 0; dict->val.d[i].val; i++)
;//Silent empty body for loop for clang
//fprintf(stderr, "be_add_keypair() i = %d\n",i);
@ -581,10 +587,11 @@ int be_add_keypair(be_node *dict, const char *str, be_node *node)
int len = strlen(str);
long long int sllen = len;
char *_ret = (char *) malloc(sizeof(sllen) + len + 1);
if(_ret == NULL)
{
std::cerr << "(EE) " << __PRETTY_FUNCTION__ << ": ERROR. cannot allocate memory for " << len+1+sizeof(sllen) << " bytes." << std::endl;
fprintf(stderr, "(EE) bencode::be_create_str_wlen(): "
"ERROR. cannot allocate memory for %lu bytes.\n"
, len+1+sizeof(sllen) );
return 0;
}
char *ret = NULL;
@ -616,7 +623,8 @@ int be_add_list(be_node *list, be_node *node)
}
// get to end of dict.
for(i = 0; list->val.l[i]; i++);
for(i = 0; list->val.l[i]; i++)
;//Silent empty body for loop for clang
/* realloc space */
list->val.l = (be_node **) realloc(list->val.l, (i + 2) * sizeof(*list->val.l));