diff options
author | Bruce Momjian <bruce@momjian.us> | 2020-12-24 18:21:37 -0500 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2020-12-24 18:21:37 -0500 |
commit | 558a6e8e21367dae9a294291337be10a8a4afd0a (patch) | |
tree | 371a3456d7f9bac849761bdc53a83bcdce1cb793 /src | |
parent | c3826f831e6e63e13a749fd3ab9fd7106707b549 (diff) | |
download | postgresql-558a6e8e21367dae9a294291337be10a8a4afd0a.tar.gz postgresql-558a6e8e21367dae9a294291337be10a8a4afd0a.zip |
revert removal of hex_decode() from ecpg from commit c3826f831e
ecpglib on certain platforms can't handle the pg_log_fatal calls from
libraries. This was reported by the buildfarm. It needs a refactoring
and return value change if it is later removed.
Backpatch-through: master
Diffstat (limited to 'src')
-rw-r--r-- | src/interfaces/ecpg/ecpglib/data.c | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/src/interfaces/ecpg/ecpglib/data.c b/src/interfaces/ecpg/ecpglib/data.c index 326de71cb1b..6bc91ef7eb6 100644 --- a/src/interfaces/ecpg/ecpglib/data.c +++ b/src/interfaces/ecpg/ecpglib/data.c @@ -5,7 +5,6 @@ #include <math.h> -#include "common/hex_decode.h" #include "ecpgerrno.h" #include "ecpglib.h" #include "ecpglib_extern.h" @@ -137,6 +136,57 @@ ecpg_hex_dec_len(unsigned srclen) return srclen >> 1; } +static inline char +get_hex(char c) +{ + static const int8 hexlookup[128] = { + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + }; + int res = -1; + + if (c > 0 && c < 127) + res = hexlookup[(unsigned char) c]; + + return (char) res; +} + +static unsigned +hex_decode(const char *src, unsigned len, char *dst) +{ + const char *s, + *srcend; + char v1, + v2, + *p; + + srcend = src + len; + s = src; + p = dst; + while (s < srcend) + { + if (*s == ' ' || *s == '\n' || *s == '\t' || *s == '\r') + { + s++; + continue; + } + v1 = get_hex(*s++) << 4; + if (s >= srcend) + return -1; + + v2 = get_hex(*s++); + *p++ = v1 | v2; + } + + return p - dst; +} + unsigned ecpg_hex_encode(const char *src, unsigned len, char *dst) { |