off-by-one ... arg
authormiker <miker@9efc2488-bf62-4759-914b-345cdb29e865>
Mon, 27 Nov 2006 17:27:22 +0000 (17:27 +0000)
committermiker <miker@9efc2488-bf62-4759-914b-345cdb29e865>
Mon, 27 Nov 2006 17:27:22 +0000 (17:27 +0000)
git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@803 9efc2488-bf62-4759-914b-345cdb29e865

src/utils/utils.c

index ffe738e..3c7a2d6 100644 (file)
@@ -254,7 +254,7 @@ int buffer_add_char(growing_buffer* gb, char c) {
 char* uescape( const char* string, int size, int full_escape ) {
 
        growing_buffer* buf = buffer_init(size + 64);
-       int clen = 1;
+       int clen = 0;
        int idx = 0;
        unsigned long int c = 0x0;
 
@@ -268,19 +268,19 @@ char* uescape( const char* string, int size, int full_escape ) {
 
                                clen = 1;
                                if (((unsigned char)string[idx] & 0xF0) == 0xF0) {
-                                       clen = 4;
+                                       clen = 3;
                                        c = (unsigned char)string[idx] ^ 0xF0;
 
                                } else if (((unsigned char)string[idx] & 0xE0) == 0xE0) {
-                                       clen = 3;
+                                       clen = 2;
                                        c = (unsigned char)string[idx] ^ 0xE0;
 
                                } else if (((unsigned char)string[idx] & 0xC0) == 0xC0) {
-                                       clen = 2;
+                                       clen = 1;
                                        c = (unsigned char)string[idx] ^ 0xC0;
                                }
 
-                               for (;clen;--clen) {
+                               for (;clen;clen--) {
 
                                        idx++; // look at the next byte
                                        c = (c << 6) | ((unsigned char)string[idx] & 0x3F); // add this byte worth