X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Futils.c;h=e750450e8bc3cf203843378e99f123a7681f86f3;hb=19be9cf7150858311f7898fa3fb525d692d02f64;hp=022ac257906d621b417a7281f9b941e64542d7c5;hpb=fa4a01e4a27dd4b3a57077acbd0e69f95d55944a;p=meshlink diff --git a/src/utils.c b/src/utils.c index 022ac257..e750450e 100644 --- a/src/utils.c +++ b/src/utils.c @@ -66,7 +66,7 @@ int bin2hex(const char *src, char *dst, int length) { int b64decode(const char *src, char *dst, int length) { int i; uint32_t triplet = 0; - unsigned char *udst = dst; + unsigned char *udst = (unsigned char *)dst; for(i = 0; i < length / 3 * 4 && src[i]; i++) { triplet |= charb64decode(src[i]) << (6 * (i & 3)); @@ -92,7 +92,7 @@ int b64decode(const char *src, char *dst, int length) { int b64encode(const char *src, char *dst, int length) { uint32_t triplet; - const unsigned char *usrc = src; + const unsigned char *usrc = (unsigned char *)src; int si = length / 3 * 3; int di = length / 3 * 4; @@ -137,15 +137,17 @@ int b64encode(const char *src, char *dst, int length) { #endif const char *winerror(int err) { - static char buf[1024], *newline; + static char buf[1024], *ptr; + + ptr = buf + sprintf(buf, "(%d) ", err); if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, sizeof(buf), NULL)) { + NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), ptr, sizeof(buf) - (ptr - buf), NULL)) { strncpy(buf, "(unable to format errormessage)", sizeof(buf)); }; - if((newline = strchr(buf, '\r'))) - *newline = '\0'; + if((ptr = strchr(buf, '\r'))) + *ptr = '\0'; return buf; }