]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/trace/visbuf.c
ncurses 6.4 - patch 20240420
[ncurses.git] / ncurses / trace / visbuf.c
index 17b590a725291a1851b654c7d5951273f6eed71a..590e42306f5163acfceb0c0baa2959006b309520 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2001-2017,2019 Free Software Foundation, Inc.              *
+ * Copyright 2019-2021,2023 Thomas E. Dickey                                *
+ * Copyright 2001-2016,2017 Free Software Foundation, Inc.                  *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -42,7 +43,7 @@
 #include <tic.h>
 #include <ctype.h>
 
-MODULE_ID("$Id: visbuf.c,v 1.50 2019/02/16 21:18:42 tom Exp $")
+MODULE_ID("$Id: visbuf.c,v 1.54 2023/05/27 20:13:10 tom Exp $")
 
 #define NUM_VISBUFS 4
 
@@ -66,7 +67,9 @@ static const char r_brace[] = StringOf(R_BRACE);
 static char *
 _nc_vischar(char *tp, unsigned c LIMIT_ARG)
 {
-    if (c == '"' || c == '\\') {
+    if (tp == NULL) {
+       return NULL;
+    } else if (c == '"' || c == '\\') {
        *tp++ = '\\';
        *tp++ = (char) c;
     } else if (is7bits((int) c) && (isgraph((int) c) || c == ' ')) {
@@ -282,7 +285,7 @@ _nc_viswibuf(const wint_t *buf)
 
 /* use these functions for displaying parts of a line within a window */
 NCURSES_EXPORT(const char *)
-_nc_viscbuf2(int bufnum, const NCURSES_CH_T * buf, int len)
+_nc_viscbuf2(int bufnum, const NCURSES_CH_T *buf, int len)
 {
     char *result = _nc_trace_buf(bufnum, (size_t) BUFSIZ);
 
@@ -338,7 +341,7 @@ _nc_viscbuf2(int bufnum, const NCURSES_CH_T * buf, int len)
                        if (PUTC_n <= 0 || buf[j].chars[PUTC_i] > 255) {
                            _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
                                        "{%d:\\u%lx}",
-                                       wcwidth(buf[j].chars[PUTC_i]),
+                                       _nc_wacs_width(buf[j].chars[PUTC_i]),
                                        (unsigned long) buf[j].chars[PUTC_i]);
                            (void) _nc_trace_bufcat(bufnum, temp);
                            break;
@@ -370,7 +373,7 @@ _nc_viscbuf2(int bufnum, const NCURSES_CH_T * buf, int len)
 }
 
 NCURSES_EXPORT(const char *)
-_nc_viscbuf(const NCURSES_CH_T * buf, int len)
+_nc_viscbuf(const NCURSES_CH_T *buf, int len)
 {
     return _nc_viscbuf2(0, buf, len);
 }