[PATCH 1/9] util: Add support for QUOTE_0_TERMINATED in user_style to ptrintstr_ex
Eugene Syromyatnikov
evgsyr at gmail.com
Tue Oct 11 22:38:13 UTC 2016
This enables printing size-limited (expectedly) ASCIZ strings.
---
util.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/util.c b/util.c
index 23a5fdb..00148d4 100644
--- a/util.c
+++ b/util.c
@@ -820,13 +820,13 @@ printstr_ex(struct tcb *tcp, long addr, long len, unsigned int user_style)
outstr = xmalloc(outstr_size);
}
- size = max_strlen;
+ size = max_strlen + 1;
if (len == -1) {
/*
* Treat as a NUL-terminated string: fetch one byte more
* because string_quote may look one byte ahead.
*/
- if (umovestr(tcp, addr, size + 1, str) < 0) {
+ if (umovestr(tcp, addr, size, str) < 0) {
printaddr(addr);
return;
}
@@ -844,11 +844,23 @@ printstr_ex(struct tcb *tcp, long addr, long len, unsigned int user_style)
style |= user_style;
+ if (style & QUOTE_0_TERMINATED) {
+ if (size) {
+ --size;
+ } else {
+ tprints((len == -1) || (len == 0) ? "\"\"" : "\"\"...");
+ return;
+ }
+ }
+ if (size > max_strlen)
+ size = max_strlen;
+
/* If string_quote didn't see NUL and (it was supposed to be ASCIZ str
* or we were requested to print more than -s NUM chars)...
*/
ellipsis = (string_quote(str, outstr, size, style) &&
- (len < 0 || (unsigned long) len > max_strlen));
+ ((style & QUOTE_0_TERMINATED) ||
+ (unsigned long) len > max_strlen));
tprints(outstr);
if (ellipsis)
--
1.7.10.4
More information about the Strace-devel
mailing list