mirror of
https://github.com/yarrick/iodine.git
synced 2024-12-25 09:07:49 +00:00
Added one test, fixed problems
This commit is contained in:
parent
5f74a079a6
commit
8e0db6ca54
13
read.c
13
read.c
@ -38,7 +38,7 @@ readname_loop(char *packet, char **src, char *dst, size_t length, size_t loop)
|
||||
if((c & 0xc0) == 0xc0) {
|
||||
dummy = packet + (((s[-1] & 0x3f) << 8) | s[0]);
|
||||
len += readname_loop(packet, &dummy, d, length - len, loop - 1);
|
||||
break;
|
||||
goto end;
|
||||
}
|
||||
|
||||
while(c && len < length - 1) {
|
||||
@ -48,16 +48,19 @@ readname_loop(char *packet, char **src, char *dst, size_t length, size_t loop)
|
||||
c--;
|
||||
}
|
||||
|
||||
if (len < length - 1) {
|
||||
if (len >= length - 1) {
|
||||
break; /* We used up all space */
|
||||
}
|
||||
|
||||
if (*s != 0)
|
||||
if (*s != 0) {
|
||||
*d++ = '.';
|
||||
len++;
|
||||
}
|
||||
}
|
||||
(*src) = s+1;
|
||||
|
||||
dst[len++] = '\0';
|
||||
|
||||
end:
|
||||
(*src) = s+1;
|
||||
return len;
|
||||
}
|
||||
|
||||
|
10
test.c
10
test.c
@ -122,7 +122,10 @@ test_readname()
|
||||
"\x3FzBCDEFGHIJKLMNOPQURSTUVXYZ0123456789abcdefghijklmnopqrstuvxyzAA"
|
||||
"\x3FzBCDEFGHIJKLMNOPQURSTUVXYZ0123456789abcdefghijklmnopqrstuvxyzAA"
|
||||
"\x3FzBCDEFGHIJKLMNOPQURSTUVXYZ0123456789abcdefghijklmnopqrstuvxyzAA"
|
||||
"\x00\x01\x00\x01";
|
||||
"\x00\x00\x01\x00\x01";
|
||||
char onejump[] =
|
||||
"AA\x81\x80\x00\x01\x00\x00\x00\x00\x00\x00"
|
||||
"\x02hh\xc0\x15\x00\x01\x00\x01\x05zBCDE\x00";
|
||||
char buf[1024];
|
||||
char *data;
|
||||
int rv;
|
||||
@ -148,6 +151,11 @@ test_readname()
|
||||
rv = readname(longname, &data, buf, 256);
|
||||
assert(buf[256] == '\a');
|
||||
|
||||
bzero(buf, sizeof(buf));
|
||||
data = onejump + sizeof(HEADER);
|
||||
rv = readname(onejump, &data, buf, 256);
|
||||
assert(rv == 9);
|
||||
|
||||
printf("OK\n");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user