File: | src/mod/xml_int/mod_xml_rpc/../../../../libs/xmlrpc-c/lib/libutil/make_printable.c |
Location: | line 37, column 43 |
Description: | The left operand of '==' is a garbage value |
1 | #define _XOPEN_SOURCE700 600 /* Make sure strdup() is in <string.h> */ | |||
2 | ||||
3 | #include <stdarg.h> | |||
4 | #include <string.h> | |||
5 | #include <stdio.h> | |||
6 | #include <stdlib.h> | |||
7 | #include <ctype.h> | |||
8 | ||||
9 | #include "xmlrpc_config.h" | |||
10 | #include "xmlrpc-c/string_int.h" | |||
11 | ||||
12 | ||||
13 | ||||
14 | const char * | |||
15 | xmlrpc_makePrintable_lp(const char * const input, | |||
16 | size_t const inputLength) { | |||
17 | /*---------------------------------------------------------------------------- | |||
18 | Convert an arbitrary string of characters in length-pointer form to | |||
19 | printable ASCII. E.g. convert newlines to "\n". | |||
20 | ||||
21 | Return the result in newly malloc'ed storage. Return NULL if we can't | |||
22 | get the storage. | |||
23 | -----------------------------------------------------------------------------*/ | |||
24 | char * output; | |||
25 | ||||
26 | output = malloc(inputLength*4+1); | |||
27 | /* Worst case, we render a character like \x01 -- 4 characters */ | |||
28 | ||||
29 | if (output != NULL((void*)0)) { | |||
30 | unsigned int inputCursor, outputCursor; | |||
31 | ||||
32 | for (inputCursor = 0, outputCursor = 0; | |||
33 | inputCursor < inputLength; | |||
34 | ++inputCursor) { | |||
35 | ||||
36 | if (0) { | |||
37 | } else if (input[inputCursor] == '\\') { | |||
| ||||
38 | output[outputCursor++] = '\\'; | |||
39 | output[outputCursor++] = '\\'; | |||
40 | } else if (input[inputCursor] == '\n') { | |||
41 | output[outputCursor++] = '\\'; | |||
42 | output[outputCursor++] = 'n'; | |||
43 | } else if (input[inputCursor] == '\t') { | |||
44 | output[outputCursor++] = '\\'; | |||
45 | output[outputCursor++] = 't'; | |||
46 | } else if (input[inputCursor] == '\a') { | |||
47 | output[outputCursor++] = '\\'; | |||
48 | output[outputCursor++] = 'a'; | |||
49 | } else if (input[inputCursor] == '\r') { | |||
50 | output[outputCursor++] = '\\'; | |||
51 | output[outputCursor++] = 'r'; | |||
52 | } else if (isprint(input[inputCursor])((*__ctype_b_loc ())[(int) ((input[inputCursor]))] & (unsigned short int) _ISprint)) { | |||
53 | output[outputCursor++] = input[inputCursor]; | |||
54 | } else { | |||
55 | snprintf(&output[outputCursor], 5, "\\x%02x", | |||
56 | input[inputCursor]); | |||
57 | outputCursor += 4; | |||
58 | } | |||
59 | } | |||
60 | output[outputCursor++] = '\0'; | |||
61 | } | |||
62 | return output; | |||
63 | } | |||
64 | ||||
65 | ||||
66 | ||||
67 | const char * | |||
68 | xmlrpc_makePrintable(const char * const input) { | |||
69 | /*---------------------------------------------------------------------------- | |||
70 | Convert an arbitrary string of characters (NUL-terminated, though) to | |||
71 | printable ASCII. E.g. convert newlines to "\n". | |||
72 | ||||
73 | Return the result in newly malloc'ed storage. Return NULL if we can't | |||
74 | get the storage. | |||
75 | -----------------------------------------------------------------------------*/ | |||
76 | return xmlrpc_makePrintable_lp(input, strlen(input)); | |||
77 | } | |||
78 | ||||
79 | ||||
80 | ||||
81 | const char * | |||
82 | xmlrpc_makePrintableChar(char const input) { | |||
83 | /*---------------------------------------------------------------------------- | |||
84 | Return an ASCIIZ string consisting of the character 'input', | |||
85 | properly escaped so as to be printable. E.g., in C notation, '\n' | |||
86 | turns into "\\n" | |||
87 | -----------------------------------------------------------------------------*/ | |||
88 | const char * retval; | |||
89 | ||||
90 | if (input == '\0') | |||
| ||||
91 | retval = strdup("\\0")(__extension__ (__builtin_constant_p ("\\0") && ((size_t )(const void *)(("\\0") + 1) - (size_t)(const void *)("\\0") == 1) ? (((const char *) ("\\0"))[0] == '\0' ? (char *) calloc ( (size_t) 1, (size_t) 1) : ({ size_t __len = strlen ("\\0") + 1 ; char *__retval = (char *) malloc (__len); if (__retval != ( (void*)0)) __retval = (char *) memcpy (__retval, "\\0", __len ); __retval; })) : __strdup ("\\0"))); | |||
92 | else { | |||
93 | char buffer[2]; | |||
94 | ||||
95 | buffer[0] = input; | |||
96 | buffer[1] = '\0'; | |||
97 | ||||
98 | retval = xmlrpc_makePrintable(buffer); | |||
99 | } | |||
100 | return retval; | |||
101 | } |