Skip to content

Commit a028c71

Browse files
committed
base_uint cleanups:
* Remove unused and broken reverse iterators * Use charUnHex instead of rigging up yet another unhexer
1 parent 386eabb commit a028c71

File tree

1 file changed

+23
-66
lines changed

1 file changed

+23
-66
lines changed

src/ripple/types/api/base_uint.h

+23-66
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,6 @@ class base_uint
8989
const_iterator cbegin() const { return data(); }
9090
const_iterator cend() const { return data()+bytes; }
9191

92-
reverse_iterator rbegin() { return end(); }
93-
reverse_iterator rend() { return begin(); }
94-
const_reverse_iterator rbegin() const { return end(); }
95-
const_reverse_iterator rend() const { return begin(); }
96-
const_reverse_iterator crbegin() const { return cend(); }
97-
const_reverse_iterator crend() const { return cbegin(); }
98-
9992
/** Value hashing function.
10093
The seed prevents crafted inputs from causing degenarate parent containers.
10194
*/
@@ -303,42 +296,26 @@ class base_uint
303296
hash_append (h, a.pn);
304297
}
305298

306-
void SetHexExact (const char* psz)
299+
bool SetHexExact (const char* psz)
307300
{
308301
// must be precisely the correct number of hex digits
309-
static signed char phexdigit[256] =
310-
{
311-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
312-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
313-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
314-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
315-
316-
-1, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, -1, -1, -1, -1, -1, -1, -1, -1, -1,
317-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
318-
-1, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, -1, -1, -1, -1, -1, -1, -1, -1, -1,
319-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
320-
321-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
322-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
323-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
324-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
325-
326-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
327-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
328-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
329-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
330-
};
331-
332-
char* pOut = reinterpret_cast<char*> (pn);
302+
unsigned char* pOut = begin ();
333303

334304
for (int i = 0; i < sizeof (pn); ++i)
335305
{
336-
*pOut = phexdigit[*psz++] << 4;
337-
*pOut++ |= phexdigit[*psz++];
306+
auto cHigh = charUnHex(*psz++);
307+
auto cLow = charUnHex(*psz++);
308+
309+
if (cHigh == -1 || cLow == -1)
310+
return false;
311+
312+
*pOut++ = (cHigh << 4) | cLow;
338313
}
339314

340315
assert (*psz == 0);
341-
assert (pOut == reinterpret_cast<char*> (end ()));
316+
assert (pOut == end ());
317+
318+
return true;
342319
}
343320

344321
// Allow leading whitespace.
@@ -355,35 +332,11 @@ class base_uint
355332
if (!bStrict && psz[0] == '0' && tolower (psz[1]) == 'x')
356333
psz += 2;
357334

358-
// hex char to int
359-
static signed char phexdigit[256] =
360-
{
361-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
362-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
363-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
364-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
365-
366-
-1, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, -1, -1, -1, -1, -1, -1, -1, -1, -1,
367-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
368-
-1, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, -1, -1, -1, -1, -1, -1, -1, -1, -1,
369-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
370-
371-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
372-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
373-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
374-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
375-
376-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
377-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
378-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
379-
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
380-
};
381-
382335
const unsigned char* pEnd = reinterpret_cast<const unsigned char*> (psz);
383336
const unsigned char* pBegin = pEnd;
384337

385338
// Find end.
386-
while (phexdigit[*pEnd] >= 0)
339+
while (charUnHex(*pEnd) != -1)
387340
pEnd++;
388341

389342
// Take only last digits of over long string.
@@ -395,15 +348,19 @@ class base_uint
395348
zero ();
396349

397350
if ((pEnd - pBegin) & 1)
398-
*pOut++ = phexdigit[*pBegin++];
351+
*pOut++ = charUnHex(*pBegin++);
399352

400353
while (pBegin != pEnd)
401354
{
402-
unsigned char cHigh = phexdigit[*pBegin++] << 4;
403-
unsigned char cLow = pBegin == pEnd
404-
? 0
405-
: phexdigit[*pBegin++];
406-
*pOut++ = cHigh | cLow;
355+
auto cHigh = charUnHex(*pBegin++);
356+
auto cLow = pBegin == pEnd
357+
? 0
358+
: charUnHex(*pBegin++);
359+
360+
if (cHigh == -1 || cLow == -1)
361+
return false;
362+
363+
*pOut++ = (cHigh << 4) | cLow;
407364
}
408365

409366
return !*pEnd;

0 commit comments

Comments
 (0)