Browse Source

Add a safe strcmp helper function

master
Con Kolivas 11 years ago
parent
commit
2b86f9bde1
  1. 21
      src/libckpool.c
  2. 1
      src/libckpool.h

21
src/libckpool.c

@ -1061,6 +1061,27 @@ void b58tobin(char *b58bin, const char *b58)
}
}
/* Does a safe string comparison tolerating zero length and NULL strings */
int safecmp(const char *a, const char *b)
{
int lena, lenb;
if (unlikely(!a || !b)) {
if (a != b)
return -1;
return 0;
}
lena = strlen(a);
lenb = strlen(b);
if (unlikely(!lena || !lenb)) {
if (lena != lenb)
return -1;
return 0;
}
return (strcmp(a, b));
}
static const char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/* Return a malloced string of *src encoded into mime base 64 */

1
src/libckpool.h

@ -414,6 +414,7 @@ bool _hex2bin(void *p, const void *vhexstr, size_t len, const char *file, const
#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);
int safecmp(const char *a, const char *b);
void address_to_pubkeytxn(char *pkh, const char *addr);
int ser_number(uchar *s, int32_t val);

Loading…
Cancel
Save