From 218912f6649942e736d5234e96f1a5c6367713d1 Mon Sep 17 00:00:00 2001 From: Steve Gonczi Date: Fri, 25 Nov 2016 17:37:18 -0600 Subject: 7575 mdb autoformatter emits an unexpected leading \n when printing large, formatted strings Reviewed by: Pavel Zakharov Reviewed by: Matthew Ahrens Reviewed by: Robert Mustacchi Approved by: Richard Lowe --- usr/src/cmd/mdb/common/mdb/mdb_io.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/usr/src/cmd/mdb/common/mdb/mdb_io.c b/usr/src/cmd/mdb/common/mdb/mdb_io.c index 8b4f1aaaef..84e7c92784 100644 --- a/usr/src/cmd/mdb/common/mdb/mdb_io.c +++ b/usr/src/cmd/mdb/common/mdb/mdb_io.c @@ -25,6 +25,7 @@ /* * Copyright (c) 2012, Joyent, Inc. All rights reserved. + * Copyright (c) 2016 by Delphix. All rights reserved. */ /* @@ -1513,7 +1514,17 @@ iob_doprnt(mdb_iob_t *iob, const char *format, varglist_t *ap) /* * If the string and the option altstr won't fit on this line * and auto-wrap is set (default), skip to the next line. + * If the string contains \n, and the \n terminated substring + * + altstr is shorter than the above, use the shorter lf_len. */ + if (u.str != NULL) { + char *np = strchr(u.str, '\n'); + if (np != NULL) { + int lf_len = (np - u.str) + altlen; + if (lf_len < width) + width = lf_len; + } + } if (IOB_WRAPNOW(iob, width)) mdb_iob_nl(iob); -- cgit v1.2.3