Thu, 13 Nov 2014 00:56:55 -0500
Remove -Wno-sign-compare and backport fixes from default.
| 2086 | 1 | /* This file is part of the Project Athena Zephyr Notification System. |
| 2 | * It contains source for the ZReadAscii function. | |
| 3 | * | |
| 4 | * Created by: Robert French | |
| 5 | * | |
| 6 | * Copyright (c) 1987, 1990 by the Massachusetts Institute of Technology. | |
| 7 | * For copying and distribution information, see the file | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
8 | * "mit-copyright.h". |
| 2086 | 9 | */ |
| 10 | ||
|
8792
b0645c9dc276
[gaim-migrate @ 9554]
Christian Hammond <chipx86@chipx86.com>
parents:
2086
diff
changeset
|
11 | #include "internal.h" |
| 2086 | 12 | |
|
36256
a437550a9308
Remove -Wno-sign-compare and backport fixes from default.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
36029
diff
changeset
|
13 | #define Z_cnvt_xtoi(c) ((temp=(c)-'0'),(temp<10)?(int)temp:((temp-='A'-'9'-1),(temp<16)?(int)temp:-1)) |
| 2086 | 14 | |
| 15 | Code_t ZReadAscii(ptr, len, field, num) | |
| 16 | char *ptr; | |
| 17 | int len; | |
| 18 | unsigned char *field; | |
| 19 | int num; | |
| 20 | { | |
| 21 | int i; | |
| 22 | unsigned int hexbyte; | |
| 23 | register int c1, c2; | |
| 24 | register unsigned int temp; | |
| 25 | ||
| 26 | for (i=0;i<num;i++) { | |
| 27 | if (*ptr == ' ') { | |
| 28 | ptr++; | |
| 29 | if (--len < 0) | |
| 30 | return ZERR_BADFIELD; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
31 | } |
| 2086 | 32 | if (ptr[0] == '0' && ptr[1] == 'x') { |
| 33 | ptr += 2; | |
| 34 | len -= 2; | |
| 35 | if (len < 0) | |
| 36 | return ZERR_BADFIELD; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
37 | } |
| 2086 | 38 | c1 = Z_cnvt_xtoi(ptr[0]); |
| 39 | if (c1 < 0) | |
| 40 | return ZERR_BADFIELD; | |
| 41 | c2 = Z_cnvt_xtoi(ptr[1]); | |
| 42 | if (c2 < 0) | |
| 43 | return ZERR_BADFIELD; | |
| 44 | hexbyte = (c1 << 4) | c2; | |
| 45 | field[i] = hexbyte; | |
| 46 | ptr += 2; | |
| 47 | len -= 2; | |
| 48 | if (len < 0) | |
| 49 | return ZERR_BADFIELD; | |
| 50 | } | |
| 51 | ||
| 52 | return *ptr ? ZERR_BADFIELD : ZERR_NONE; | |
| 53 | } | |
| 54 | ||
| 55 | Code_t ZReadAscii32(ptr, len, value_ptr) | |
| 56 | char *ptr; | |
| 57 | int len; | |
| 58 | unsigned long *value_ptr; | |
| 59 | { | |
| 60 | unsigned char buf[4]; | |
|
35993
bd0a2508b477
Fix some other coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
61 | unsigned long value = 0; |
| 2086 | 62 | Code_t retval; |
| 63 | ||
| 64 | retval = ZReadAscii(ptr, len, buf, 4); | |
| 65 | if (retval != ZERR_NONE) | |
| 66 | return retval; | |
|
36029
cd7db320cf5c
Fix coverity regression warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35993
diff
changeset
|
67 | value |= (unsigned long)buf[0] << 24; |
|
35993
bd0a2508b477
Fix some other coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
68 | value |= buf[1] << 16; |
|
bd0a2508b477
Fix some other coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
69 | value |= buf[2] << 8; |
|
bd0a2508b477
Fix some other coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
70 | value |= buf[3]; |
|
bd0a2508b477
Fix some other coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
31294
diff
changeset
|
71 | *value_ptr = value; |
| 2086 | 72 | return ZERR_NONE; |
| 73 | } | |
| 74 | ||
| 75 | Code_t ZReadAscii16(ptr, len, value_ptr) | |
| 76 | char *ptr; | |
| 77 | int len; | |
| 78 | unsigned short *value_ptr; | |
| 79 | { | |
| 80 | unsigned char buf[2]; | |
| 81 | Code_t retval; | |
| 82 | ||
| 83 | retval = ZReadAscii(ptr, len, buf, 2); | |
| 84 | if (retval != ZERR_NONE) | |
| 85 | return retval; | |
| 86 | *value_ptr = (buf[0] << 8) | buf[1]; | |
| 87 | return ZERR_NONE; | |
| 88 | } | |
| 89 |