diff options
Diffstat (limited to 'util')
-rw-r--r-- | util/ChangeLog | 4 | ||||
-rw-r--r-- | util/ttyio.c | 19 |
2 files changed, 19 insertions, 4 deletions
diff --git a/util/ChangeLog b/util/ChangeLog index 4b568949c..72a7f5d5f 100644 --- a/util/ChangeLog +++ b/util/ChangeLog @@ -1,3 +1,7 @@ +Thu Mar 2 15:37:46 CET 2000 Werner Koch <[email protected]> + + * ttyio.c (tty_print_utf8_string2): New to allow a max output size. + Wed Feb 23 10:07:57 CET 2000 Werner Koch <[email protected]> * miscutil.c (asctimestamp): Fix for possible buffer overflow by diff --git a/util/ttyio.c b/util/ttyio.c index 35e0d318f..e2c1f8496 100644 --- a/util/ttyio.c +++ b/util/ttyio.c @@ -236,7 +236,7 @@ tty_print_string( byte *p, size_t n ) } void -tty_print_utf8_string( byte *p, size_t n ) +tty_print_utf8_string2( byte *p, size_t n, size_t max_n ) { size_t i; char *buf; @@ -251,15 +251,26 @@ tty_print_utf8_string( byte *p, size_t n ) } if( i < n ) { buf = utf8_to_native( p, n ); + if( strlen( buf ) > max_n ) { + buf[max_n] = 0; + } + /*(utf8 conversion already does the control character quoting)*/ tty_printf("%s", buf ); m_free( buf ); } - else + else { + if( n > max_n ) { + n = max_n; + } tty_print_string( p, n ); + } } - - +void +tty_print_utf8_string( byte *p, size_t n ) +{ + tty_print_utf8_string( p, n, n ) +} static char * |