X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/blobdiff_plain/09fbf4d0a21c9cad25cc3f12b1e3f365f850eb94..0335afec2c33fefcd6d3cb2c39d014ab2519b2c2:/codec/baseconv.c?ds=sidebyside diff --git a/codec/baseconv.c b/codec/baseconv.c index bdb850f..53fceb2 100644 --- a/codec/baseconv.c +++ b/codec/baseconv.c @@ -35,6 +35,7 @@ #include "alloc.h" #include "codec.h" #include "dstr.h" +#include "macros.h" #include "sub.h" #include "base64.h" @@ -279,7 +280,7 @@ enum { #define PUTWRAP(x) WRAP({ \ char ch = encodemap[x]; \ - if (f & CDCF_LOWERC) ch = tolower((unsigned char)ch); \ + if (f & CDCF_LOWERC) ch = TOLOWER(ch); \ DPUTC(d, ch); \ }) @@ -350,9 +351,9 @@ static int ctxn##_dodecode(ctxn##_ctx *ctx, \ case 0: \ break; \ case CDCF_LOWERC: \ - if (isupper(ch)) goto badch; \ + if (ISUPPER(ch)) goto badch; \ default: \ - ch = toupper(ch); \ + ch = TOUPPER(ch); \ } \ x = decodemap[ch]; \ switch (x) { \ @@ -363,8 +364,8 @@ static int ctxn##_dodecode(ctxn##_ctx *ctx, \ case PC: \ if (f & CDCF_IGNEQMID) break; \ if (f & CDCF_NOEQPAD) goto badch; \ - if (st == ST_MAIN && \ - !(f & CDCF_IGNZPAD) && (a & ((1 << nb) - 1))) \ + if (st == ST_MAIN && !(f & CDCF_IGNZPAD) && \ + ((nb && !(nb%wd)) || (a & ((1 << nb) - 1)))) \ return (CDCERR_INVZPAD); \ st = ST_PAD; \ if (!(f & CDCF_IGNEQPAD)) { \ @@ -386,8 +387,8 @@ static int ctxn##_dodecode(ctxn##_ctx *ctx, \ } \ } \ } else { \ - if (st == ST_MAIN && \ - !(f & CDCF_IGNZPAD) && (a & ((1 << nb) - 1))) \ + if (st == ST_MAIN && !(f & CDCF_IGNZPAD) && \ + ((nb && !(nb%wd)) || (a & ((1 << nb) - 1)))) \ return (CDCERR_INVZPAD); \ if (!(f & (CDCF_IGNEQPAD | CDCF_IGNEQMID | CDCF_NOEQPAD)) && nb) \ return (CDCERR_INVEQPAD); \