Show More
@@ -15,14 +15,13 b' static int hexdigit(char c)' | |||
|
15 | 15 | { |
|
16 | 16 | if (c >= '0' && c <= '9') |
|
17 | 17 | return c - '0'; |
|
18 | ||
|
18 | if (c >= 'a' && c <= 'f') | |
|
19 | return c - 'a' + 10; | |
|
19 | 20 | if (c >= 'A' && c <= 'F') |
|
20 | 21 | return c - 'A' + 10; |
|
21 | 22 | |
|
22 | if (c >= 'a' && c <= 'f') | |
|
23 |
|
|
|
24 | ||
|
25 | return -1; | |
|
23 | PyErr_SetString(PyExc_ValueError, "input contains non-hex character"); | |
|
24 | return 0; | |
|
26 | 25 | } |
|
27 | 26 | |
|
28 | 27 | /* |
@@ -30,43 +29,21 b' static int hexdigit(char c)' | |||
|
30 | 29 | */ |
|
31 | 30 | static PyObject *unhexlify(const char *str, int len) |
|
32 | 31 | { |
|
33 |
PyObject *ret |
|
|
32 | PyObject *ret; | |
|
34 | 33 | const char *c; |
|
35 | 34 | char *d; |
|
36 | 35 | |
|
37 | if (len % 2) { | |
|
38 | PyErr_SetString(PyExc_ValueError, | |
|
39 | "input is not even in length"); | |
|
40 | goto bail; | |
|
41 | } | |
|
42 | ||
|
43 | 36 | ret = PyString_FromStringAndSize(NULL, len / 2); |
|
44 | 37 | if (!ret) |
|
45 | goto bail; | |
|
38 | return NULL; | |
|
46 | 39 | |
|
47 |
d = PyString_A |
|
|
48 | if (!d) | |
|
49 | goto bail; | |
|
50 | ||
|
40 | d = PyString_AS_STRING(ret); | |
|
51 | 41 | for (c = str; c < str + len;) { |
|
52 | 42 | int hi = hexdigit(*c++); |
|
53 | 43 | int lo = hexdigit(*c++); |
|
54 | ||
|
55 | if (hi == -1 || lo == -1) { | |
|
56 | PyErr_SetString(PyExc_ValueError, | |
|
57 | "input contains non-hex character"); | |
|
58 | goto bail; | |
|
59 | } | |
|
60 | ||
|
61 | 44 | *d++ = (hi << 4) | lo; |
|
62 | 45 | } |
|
63 | 46 | |
|
64 | goto done; | |
|
65 | ||
|
66 | bail: | |
|
67 | Py_XDECREF(ret); | |
|
68 | ret = NULL; | |
|
69 | done: | |
|
70 | 47 | return ret; |
|
71 | 48 | } |
|
72 | 49 |
General Comments 0
You need to be logged in to leave comments.
Login now