Skip to content

Commit 558a6e8

Browse files
committed
revert removal of hex_decode() from ecpg from commit c3826f8
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
1 parent c3826f8 commit 558a6e8

File tree

1 file changed

+51
-1
lines changed
  • src/interfaces/ecpg/ecpglib

1 file changed

+51
-1
lines changed

src/interfaces/ecpg/ecpglib/data.c

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include <math.h>
77

8-
#include "common/hex_decode.h"
98
#include "ecpgerrno.h"
109
#include "ecpglib.h"
1110
#include "ecpglib_extern.h"
@@ -137,6 +136,57 @@ ecpg_hex_dec_len(unsigned srclen)
137136
return srclen >> 1;
138137
}
139138

139+
static inline char
140+
get_hex(char c)
141+
{
142+
static const int8 hexlookup[128] = {
143+
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
144+
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
145+
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
146+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
147+
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
148+
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
149+
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
150+
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
151+
};
152+
int res = -1;
153+
154+
if (c > 0 && c < 127)
155+
res = hexlookup[(unsigned char) c];
156+
157+
return (char) res;
158+
}
159+
160+
static unsigned
161+
hex_decode(const char *src, unsigned len, char *dst)
162+
{
163+
const char *s,
164+
*srcend;
165+
char v1,
166+
v2,
167+
*p;
168+
169+
srcend = src + len;
170+
s = src;
171+
p = dst;
172+
while (s < srcend)
173+
{
174+
if (*s == ' ' || *s == '\n' || *s == '\t' || *s == '\r')
175+
{
176+
s++;
177+
continue;
178+
}
179+
v1 = get_hex(*s++) << 4;
180+
if (s >= srcend)
181+
return -1;
182+
183+
v2 = get_hex(*s++);
184+
*p++ = v1 | v2;
185+
}
186+
187+
return p - dst;
188+
}
189+
140190
unsigned
141191
ecpg_hex_encode(const char *src, unsigned len, char *dst)
142192
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy