diff --git a/read.c b/read.c
index aa5b4d5..e6f9403 100644
--- a/read.c
+++ b/read.c
@@ -41,20 +41,19 @@ readname_loop(char *packet, char **src, char *dst, size_t length, size_t loop)
 			break;
 		}
 
-		while(c && len < length - 2) {
+		while(c && len < length - 1) {
 			*d++ = *s++;
 			len++;
 
 			c--;
 		}
 
-		if (*s != 0 && len < length - 2)
+		if (*s != 0 && len < length - 1)
 			*d++ = '.';
 	}
 	(*src) = s+1;
 
-	dst[len] = '\0';
-
+	dst[len++] = '\0';
 	return len;
 }
 
diff --git a/test.c b/test.c
index e60b59d..640e72c 100644
--- a/test.c
+++ b/test.c
@@ -104,6 +104,7 @@ test_readputlong()
 	printf("OK\n");
 }
 
+
 static void
 test_readname()
 {
@@ -113,6 +114,15 @@ test_readname()
 	char infloop[] = {
 		'A', 'A', 0x81, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 		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 *data;
 	int rv;
@@ -131,6 +141,13 @@ test_readname()
 	buf[4] = '\a';
 	rv = readname(infloop, &data, buf, 4);
 	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");
 }