Fix printstr's len parameter width

We often pass syscall params and other long-sized values
as printstr(len). Truncating them to int may be a bad thing.

* defs.h: Change len parameter's type from int to long in
string_quote and printstr function declarations.
* util.c (string_quote): Special-case only len==-1, not all len<0.
(printstr): Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
diff --git a/defs.h b/defs.h
index 62f35b4..3ccd8d5 100644
--- a/defs.h
+++ b/defs.h
@@ -526,7 +526,7 @@
 extern const char *xlookup(const struct xlat *, int);
 
 extern int string_to_uint(const char *str);
-extern int string_quote(const char *, char *, int, int);
+extern int string_quote(const char *, char *, long, int);
 
 #if HAVE_LONG_LONG
 /* _l refers to the lower numbered u_arg,
@@ -550,7 +550,7 @@
 extern const char *sprintflags(const char *, const struct xlat *, int);
 extern void dumpiov(struct tcb *, int, long);
 extern void dumpstr(struct tcb *, long, int);
-extern void printstr(struct tcb *, long, int);
+extern void printstr(struct tcb *, long, long);
 extern void printnum(struct tcb *, long, const char *);
 extern void printnum_int(struct tcb *, long, const char *);
 extern void printpath(struct tcb *, long);
diff --git a/util.c b/util.c
index ea03685..d347bd8 100644
--- a/util.c
+++ b/util.c
@@ -372,21 +372,21 @@
 /*
  * Quote string `instr' of length `size'
  * Write up to (3 + `size' * 4) bytes to `outstr' buffer.
- * If `len' < 0, treat `instr' as a NUL-terminated string
+ * If `len' is -1, treat `instr' as a NUL-terminated string
  * and quote at most (`size' - 1) bytes.
  *
- * Returns 0 if len < 0 and NUL was seen, 1 otherwise.
+ * Returns 0 if len == -1 and NUL was seen, 1 otherwise.
  * Note that if len >= 0, always returns 1.
  */
 int
-string_quote(const char *instr, char *outstr, int len, int size)
+string_quote(const char *instr, char *outstr, long len, int size)
 {
 	const unsigned char *ustr = (const unsigned char *) instr;
 	char *s = outstr;
 	int usehex, c, i, eol;
 
 	eol = 0x100; /* this can never match a char */
-	if (len < 0) {
+	if (len == -1) {
 		size--;
 		eol = '\0';
 	}
@@ -486,7 +486,7 @@
 	*s = '\0';
 
 	/* Return zero if we printed entire ASCIZ string (didn't truncate it) */
-	if (len < 0 && ustr[i] == '\0') {
+	if (len == -1 && ustr[i] == '\0') {
 		/* We didn't see NUL yet (otherwise we'd jump to 'asciz_ended')
 		 * but next char is NUL.
 		 */
@@ -551,7 +551,7 @@
  * If string length exceeds `max_strlen', append `...' to the output.
  */
 void
-printstr(struct tcb *tcp, long addr, int len)
+printstr(struct tcb *tcp, long addr, long len)
 {
 	static char *str = NULL;
 	static char *outstr;
@@ -576,7 +576,7 @@
 			die_out_of_memory();
 	}
 
-	if (len < 0) {
+	if (len == -1) {
 		/*
 		 * Treat as a NUL-terminated string: fetch one byte more
 		 * because string_quote() quotes one byte less.
@@ -588,7 +588,9 @@
 		}
 	}
 	else {
-		size = MIN(len, max_strlen);
+		size = max_strlen;
+		if (size > (unsigned long)len)
+			size = (unsigned long)len;
 		if (umoven(tcp, addr, size, str) < 0) {
 			tprintf("%#lx", addr);
 			return;