Browse Source

Add debugging to hex2bin to know where it failed from

master
Con Kolivas 11 years ago
parent
commit
93735544ca
  1. 2
      src/ckpmsg.c
  2. 8
      src/libckpool.c
  3. 3
      src/libckpool.h

2
src/ckpmsg.c

@ -72,7 +72,7 @@ int main(int argc, char **argv)
break;
}
if (!send_unix_msg(sockd, buf)) {
LOGERR("Failed to end unix msg: %s", buf);
LOGERR("Failed to send unix msg: %s", buf);
break;
}
dealloc(buf);

8
src/libckpool.c

@ -918,7 +918,7 @@ static const int hex2bin_tbl[256] = {
};
/* Does the reverse of bin2hex but does not allocate any ram */
bool hex2bin(void *vp, const void *vhexstr, size_t len)
bool _hex2bin(void *vp, const void *vhexstr, size_t len, const char *file, const char *func, const int line)
{
const uchar *hexstr = vhexstr;
int nibble1, nibble2;
@ -928,7 +928,7 @@ bool hex2bin(void *vp, const void *vhexstr, size_t len)
while (*hexstr && len) {
if (unlikely(!hexstr[1])) {
LOGWARNING("Early end of string in hex2bin");
LOGWARNING("Early end of string in hex2bin from %s %s:%d", file, func, line);
return ret;
}
@ -938,7 +938,7 @@ bool hex2bin(void *vp, const void *vhexstr, size_t len)
nibble2 = hex2bin_tbl[idx];
if (unlikely((nibble1 < 0) || (nibble2 < 0))) {
LOGWARNING("Invalid binary encoding in hex2bin");
LOGWARNING("Invalid binary encoding in hex2bin from %s %s:%d", file, func, line);
return ret;
}
@ -949,7 +949,7 @@ bool hex2bin(void *vp, const void *vhexstr, size_t len)
if (likely(len == 0 && *hexstr == 0))
ret = true;
if (!ret)
LOGWARNING("Failed hex2bin decode");
LOGWARNING("Failed hex2bin decode from %s %s:%d", file, func, line);
return ret;
}

3
src/libckpool.h

@ -366,7 +366,8 @@ void *_ckzalloc(size_t len, const char *file, const char *func, const int line);
void _dealloc(void **ptr);
void __bin2hex(void *vs, const void *vp, size_t len);
void *bin2hex(const void *vp, size_t len);
bool hex2bin(void *p, const void *vhexstr, size_t len);
bool _hex2bin(void *p, const void *vhexstr, size_t len, const char *file, const char *func, const int line);
#define hex2bin(p, vhexstr, len) _hex2bin(p, vhexstr, len, __FILE__, __func__, __LINE__)
char *http_base64(const char *src);
void b58tobin(char *b58bin, const char *b58);

Loading…
Cancel
Save