Small fixes, not working yet

This commit is contained in:
Erik Ekman 2006-08-24 22:21:32 +00:00
parent b52787a74b
commit 783399e901
2 changed files with 20 additions and 4 deletions

7
read.c
View File

@ -41,20 +41,19 @@ readname_loop(char *packet, char **src, char *dst, size_t length, size_t loop)
break; break;
} }
while(c && len < length - 2) { while(c && len < length - 1) {
*d++ = *s++; *d++ = *s++;
len++; len++;
c--; c--;
} }
if (*s != 0 && len < length - 2) if (*s != 0 && len < length - 1)
*d++ = '.'; *d++ = '.';
} }
(*src) = s+1; (*src) = s+1;
dst[len] = '\0'; dst[len++] = '\0';
return len; return len;
} }

17
test.c
View File

@ -104,6 +104,7 @@ test_readputlong()
printf("OK\n"); printf("OK\n");
} }
static void static void
test_readname() test_readname()
{ {
@ -113,6 +114,15 @@ test_readname()
char infloop[] = { char infloop[] = {
'A', 'A', 0x81, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 'A', 'A', 0x81, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 'A', 0xc0, 0x0c, 0x00, 0x01, 0x00, 0x01 }; 0x01, 'A', 0xc0, 0x0c, 0x00, 0x01, 0x00, 0x01 };
char longname[] =
"AA\x81\x80\x00\x01\x00\x00\x00\x00\x00\x00"
"\x3FzBCDEFGHIJKLMNOPQURSTUVXYZ0123456789abcdefghijklmnopqrstuvxyzAA"
"\x3FzBCDEFGHIJKLMNOPQURSTUVXYZ0123456789abcdefghijklmnopqrstuvxyzAA"
"\x3FzBCDEFGHIJKLMNOPQURSTUVXYZ0123456789abcdefghijklmnopqrstuvxyzAA"
"\x3FzBCDEFGHIJKLMNOPQURSTUVXYZ0123456789abcdefghijklmnopqrstuvxyzAA"
"\x3FzBCDEFGHIJKLMNOPQURSTUVXYZ0123456789abcdefghijklmnopqrstuvxyzAA"
"\x3FzBCDEFGHIJKLMNOPQURSTUVXYZ0123456789abcdefghijklmnopqrstuvxyzAA"
"\x00\x01\x00\x01";
char buf[1024]; char buf[1024];
char *data; char *data;
int rv; int rv;
@ -131,6 +141,13 @@ test_readname()
buf[4] = '\a'; buf[4] = '\a';
rv = readname(infloop, &data, buf, 4); rv = readname(infloop, &data, buf, 4);
assert(buf[4] == '\a'); assert(buf[4] == '\a');
bzero(buf, sizeof(buf));
data = longname + sizeof(HEADER);
buf[256] = '\a';
rv = readname(longname, &data, buf, 256);
printf("got %d, '%s' len %d \n", rv, buf, strlen(buf));
assert(buf[256] == '\a');
printf("OK\n"); printf("OK\n");
} }