Bug Summary

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

Annotated Source Code

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
14const char *
15xmlrpc_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)) {
4
Assuming 'output' is not equal to null
5
Taking true branch
30 unsigned int inputCursor, outputCursor;
31
32 for (inputCursor = 0, outputCursor = 0;
7
Loop condition is true. Entering loop body
14
Loop condition is true. Entering loop body
23
Loop condition is true. Entering loop body
33 inputCursor < inputLength;
6
Assuming 'inputCursor' is < 'inputLength'
13
Assuming 'inputCursor' is < 'inputLength'
22
Assuming 'inputCursor' is < 'inputLength'
34 ++inputCursor) {
35
36 if (0) {
8
Taking false branch
15
Taking false branch
24
Taking false branch
37 } else if (input[inputCursor] == '\\') {
9
Taking false branch
16
Taking false branch
25
The left operand of '==' is a garbage value
38 output[outputCursor++] = '\\';
39 output[outputCursor++] = '\\';
40 } else if (input[inputCursor] == '\n') {
10
Taking false branch
17
Taking false branch
41 output[outputCursor++] = '\\';
42 output[outputCursor++] = 'n';
43 } else if (input[inputCursor] == '\t') {
11
Taking false branch
18
Taking false branch
44 output[outputCursor++] = '\\';
45 output[outputCursor++] = 't';
46 } else if (input[inputCursor] == '\a') {
12
Taking true branch
19
Taking false branch
47 output[outputCursor++] = '\\';
48 output[outputCursor++] = 'a';
49 } else if (input[inputCursor] == '\r') {
20
Taking false branch
50 output[outputCursor++] = '\\';
51 output[outputCursor++] = 'r';
52 } else if (isprint(input[inputCursor])((*__ctype_b_loc ())[(int) ((input[inputCursor]))] & (unsigned
short int) _ISprint)
) {
21
Taking false branch
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
67const char *
68xmlrpc_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));
3
Calling 'xmlrpc_makePrintable_lp'
77}
78
79
80
81const char *
82xmlrpc_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')
1
Taking false branch
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);
2
Calling 'xmlrpc_makePrintable'
99 }
100 return retval;
101}