Diff between 458e3278227563965b079ad2d3e6fc07ac4ef83f and 1e94d963a424b52be5f16b04b8138f8893493384

Changed Files

File Additions Deletions Status
monitor/packet.c +13 -1 modified

Full Patch

diff --git a/monitor/packet.c b/monitor/packet.c
index 76c3793..8003b8d 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -158,7 +158,19 @@ static void print_packet(struct timeval *tv, uint16_t index, char ident,
 	}
 
 	if (text) {
-		n = sprintf(line + pos, ": %s", text);
+		int extra_len = extra ? strlen(extra) : 0;
+		int max_len = col - len - extra_len - ts_len - 3;
+
+		n = snprintf(line + pos, max_len + 1, ": %s", text);
+		if (n > max_len) {
+			line[pos + max_len - 1] = '.';
+			line[pos + max_len - 2] = '.';
+			if (line[pos + max_len - 3] == ' ')
+				line[pos + max_len - 3] = '.';
+
+			n = max_len;
+		}
+
 		if (n > 0) {
 			pos += n;
 			len += n;