(/home/sate/Testcases/c/cve/wireshark-1.2.0/epan/to_str.c) |
| |
| 83 | | | gchar * |
| 84 | | | bytestring_to_str(const guint8 *ad, guint32 len, char punct) { |
| 85 | | | gchar *buf; |
| 86 | | | gchar *p; |
| 87 | | | int i = (int) len - 1; |
| 88 | | | guint32 octet; |
| 89 | | | size_t buflen; |
| 90 | | | |
| 91 | | | |
| 92 | | | |
| 93 | | | |
| 94 | | | |
| 95 | | | |
| 96 | | | static const gchar hex_digits[16] = |
| 97 | | | { '0', '1', '2', '3', '4', '5', '6', '7', |
| 98 | | | '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; |
| 99 | | | |
| 100 | | | if (punct) |
| 101 | | | buflen=len*3; |
| 102 | | | else |
| 103 | | | buflen=len*2 + 1; |
| 104 | | | |
| 105 | | | if (buflen < 3 || i < 0) { |
Redundant Condition
i < 0 always evaluates to false. This may be because: - There is a constant assignment to one or more of the variables involved.
- An earlier conditional statement has already ensured that i < 0 cannot be true.
- A crashing bug occurs on every path where i < 0 could have evaluated to true. Look for a preceding Null Pointer Dereference or Division By Zero warning.
|
|
| 106 | | | return ""; |
| 107 | | | } |
| 108 | | | |
| 109 | | | buf=ep_alloc(buflen); |
| 110 | | | p = &buf[buflen - 1]; |
| 111 | | | *p = '\0'; |
| 112 | | | for (;;) { |
| 113 | | | octet = ad[i]; |
| 114 | | | *--p = hex_digits[octet&0xF]; |
| 115 | | | octet >>= 4; |
| 116 | | | *--p = hex_digits[octet&0xF]; |
| 117 | | | if (i <= 0) |
| 118 | | | break; |
| 119 | | | if (punct) |
| 120 | | | *--p = punct; |
| 121 | | | i--; |
| 122 | | | } |
| 123 | | | return p; |
| 124 | | | } |
| |