From 01a84a3ac04b0947ac25c8bdea7252480cf25b44 Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Thu, 15 Jan 2015 16:46:45 +0800 Subject: [PATCH] Insure debug output fits inside terminal and buffer width. --- eval.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/eval.c b/eval.c index 944259a..2b95196 100644 --- a/eval.c +++ b/eval.c @@ -798,11 +798,16 @@ int setvar(int f, int n) #if DEBUGM int mdbugout( char *fmt, char *s1, char *s2, char *s3) { char outline[ NSTRING] ; /* global string to hold debug line text */ - int c ; /* input from kbd */ + int c, size ; /* input from kbd, output to terminal */ char *sp ; /* temp string pointer */ + /* insure debug info fits in terminal and buffer width */ + size = term.t_ncol + 1 ; + if( size > sizeof outline) + size = sizeof outline ; + /* assignment status ; variable name ; value we tried to assign */ - sprintf( outline, fmt, s1, s2, s3) ; + snprintf( outline, size, fmt, s1, s2, s3) ; /* expand '%' to "%%" so mlwrite wont bitch */ sp = outline;