summaryrefslogtreecommitdiff
path: root/system/ncurses/ncurses-6.3-20220226.patch
blob: 2f0c9c0beea75eb5b19151b200edc6796569d1a3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
# ncurses 6.3 - patch 20220226 - Thomas E. Dickey
#
# ------------------------------------------------------------------------------
#
# Ncurses 6.3 is at
# 	ftp://ftp.invisible-island.net/ncurses/
#	https://invisible-mirror.net/archives/ncurses/
#	https://ftp.gnu.org/gnu/ncurses/
#
# Patches for ncurses 6.3 can be found at
# 	ftp://ftp.invisible-island.net/ncurses/6.3
#	https://invisible-mirror.net/archives/ncurses/6.3
#
# ------------------------------------------------------------------------------
# ftp://ftp.invisible-island.net/ncurses/6.3/ncurses-6.3-20220226.patch.gz
# patch by Thomas E. Dickey <dickey@invisible-island.net>
# created  Sun Feb 27 01:00:55 UTC 2022
# ------------------------------------------------------------------------------
# NEWS                             |   13 ++++++-
# VERSION                          |    2 -
# c++/cursslk.cc                   |    6 ++-
# dist.mk                          |    4 +-
# ncurses/tinfo/alloc_entry.c      |   67 ++++++++++++++++++++-----------------
# ncurses/tinfo/write_entry.c      |    6 +--
# package/debian-mingw/changelog   |    4 +-
# package/debian-mingw64/changelog |    4 +-
# package/debian/changelog         |    4 +-
# package/mingw-ncurses.nsi        |    4 +-
# package/mingw-ncurses.spec       |    2 -
# package/ncurses.spec             |    2 -
# package/ncursest.spec            |    2 -
# progs/infocmp.c                  |   20 ++++++-----
# progs/tabs.c                     |    8 ++--
# progs/tput.c                     |   14 +++++--
# test/ncurses.c                   |    8 +++-
# 17 files changed, 104 insertions(+), 66 deletions(-)
# ------------------------------------------------------------------------------
Index: NEWS
Prereq:  1.3780 
--- ncurses-6.3-20220219+/NEWS	2022-02-20 00:40:32.000000000 +0000
+++ ncurses-6.3-20220226/NEWS	2022-02-26 23:50:53.000000000 +0000
@@ -26,7 +26,7 @@
 -- sale, use or other dealings in this Software without prior written        --
 -- authorization.                                                            --
 -------------------------------------------------------------------------------
--- $Id: NEWS,v 1.3780 2022/02/20 00:40:32 tom Exp $
+-- $Id: NEWS,v 1.3782 2022/02/26 23:50:53 tom Exp $
 -------------------------------------------------------------------------------
 
 This is a log of changes that ncurses has gone through since Zeyd started
@@ -46,6 +46,17 @@
 Changes through 1.9.9e did not credit all contributions;
 it is not possible to add this information.
 
+20220226
+	+ fix issues found with coverity:
+	  + rewrite canonical_name() function of infocmp to ensure buffer size
+	  + corrected use of original tty-modes in tput init/reset subcommands
+	  + modify tabs program to limit tab-stop values to max-columns
+	  + add limit-checks for palette rgb values in test/ncurses.c
+	+ add a few null-pointer checks to help with static-analysis.
+	+ enforce limit on number of soft-keys used in c++ binding.
+	+ adjust a buffer-limit in write_entry.c to quiet a bogus warning from
+	  gcc 12.0.1
+
 20220219
 	+ expanded description in man/resizeterm.3x
 	+ additional workaround for ImageMagick in test/picsmap.c
Index: VERSION
--- ncurses-6.3-20220219+/VERSION	2022-02-19 12:13:47.000000000 +0000
+++ ncurses-6.3-20220226/VERSION	2022-02-26 12:23:15.000000000 +0000
@@ -1 +1 @@
-5:0:10	6.3	20220219
+5:0:10	6.3	20220226
Index: c++/cursslk.cc
Prereq:  1.19 
--- ncurses-6.3-20220219+/c++/cursslk.cc	2020-07-18 19:57:11.000000000 +0000
+++ ncurses-6.3-20220226/c++/cursslk.cc	2022-02-26 17:57:23.000000000 +0000
@@ -1,6 +1,6 @@
 // * this is for making emacs happy: -*-Mode: C++;-*-
 /****************************************************************************
- * Copyright 2019,2020 Thomas E. Dickey                                     *
+ * Copyright 2019-2020,2022 Thomas E. Dickey                                *
  * Copyright 1998-2005,2012 Free Software Foundation, Inc.                  *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
@@ -36,7 +36,7 @@
 #include "cursslk.h"
 #include "cursesapp.h"
 
-MODULE_ID("$Id: cursslk.cc,v 1.19 2020/07/18 19:57:11 anonymous.maarten Exp $")
+MODULE_ID("$Id: cursslk.cc,v 1.20 2022/02/26 17:57:23 tom Exp $")
 
 Soft_Label_Key_Set::Soft_Label_Key&
   Soft_Label_Key_Set::Soft_Label_Key::operator=(char *text)
@@ -56,6 +56,8 @@
 
 void Soft_Label_Key_Set::init()
 {
+  if (num_labels > 12)
+      num_labels = 12;
   slk_array = new Soft_Label_Key[num_labels];
   for(int i=0; i < num_labels; i++) {
     slk_array[i].num = i+1;
Index: dist.mk
Prereq:  1.1467 
--- ncurses-6.3-20220219+/dist.mk	2022-02-19 12:13:47.000000000 +0000
+++ ncurses-6.3-20220226/dist.mk	2022-02-26 12:23:15.000000000 +0000
@@ -26,7 +26,7 @@
 # use or other dealings in this Software without prior written               #
 # authorization.                                                             #
 ##############################################################################
-# $Id: dist.mk,v 1.1467 2022/02/19 12:13:47 tom Exp $
+# $Id: dist.mk,v 1.1468 2022/02/26 12:23:15 tom Exp $
 # Makefile for creating ncurses distributions.
 #
 # This only needs to be used directly as a makefile by developers, but
@@ -38,7 +38,7 @@
 # These define the major/minor/patch versions of ncurses.
 NCURSES_MAJOR = 6
 NCURSES_MINOR = 3
-NCURSES_PATCH = 20220219
+NCURSES_PATCH = 20220226
 
 # We don't append the patch to the version, since this only applies to releases
 VERSION = $(NCURSES_MAJOR).$(NCURSES_MINOR)
Index: ncurses/tinfo/alloc_entry.c
Prereq:  1.66 
--- ncurses-6.3-20220219+/ncurses/tinfo/alloc_entry.c	2021-08-08 00:09:37.000000000 +0000
+++ ncurses-6.3-20220226/ncurses/tinfo/alloc_entry.c	2022-02-26 22:19:31.000000000 +0000
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright 2018-2020,2021 Thomas E. Dickey                                *
+ * Copyright 2018-2021,2022 Thomas E. Dickey                                *
  * Copyright 1998-2013,2017 Free Software Foundation, Inc.                  *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
@@ -48,7 +48,7 @@
 
 #include <tic.h>
 
-MODULE_ID("$Id: alloc_entry.c,v 1.66 2021/08/08 00:09:37 tom Exp $")
+MODULE_ID("$Id: alloc_entry.c,v 1.68 2022/02/26 22:19:31 tom Exp $")
 
 #define ABSENT_OFFSET    -1
 #define CANCELLED_OFFSET -2
@@ -62,16 +62,18 @@
 _nc_init_entry(ENTRY * const tp)
 /* initialize a terminal type data block */
 {
+    if (tp == NULL) {
 #if NO_LEAKS
-    if (tp == 0) {
-	if (stringbuf != 0) {
+	if (stringbuf != NULL) {
 	    FreeAndNull(stringbuf);
 	}
 	return;
-    }
+#else
+	_nc_err_abort("_nc_init_entry called without initialization");
 #endif
+    }
 
-    if (stringbuf == 0)
+    if (stringbuf == NULL)
 	TYPE_MALLOC(char, (size_t) MAX_STRTAB, stringbuf);
 
     next_free = 0;
@@ -84,7 +86,7 @@
 {
     ENTRY *newp = typeCalloc(ENTRY, 1);
 
-    if (newp != 0) {
+    if (newp != NULL) {
 	*newp = *oldp;
 	_nc_copy_termtype2(&(newp->tterm), &(oldp->tterm));
     }
@@ -99,26 +101,28 @@
     size_t old_next_free = next_free;
     size_t len;
 
-    if (!VALID_STRING(string))
-	string = "";
-    len = strlen(string) + 1;
-
-    if (len == 1 && next_free != 0) {
-	/*
-	 * Cheat a little by making an empty string point to the end of the
-	 * previous string.
-	 */
-	if (next_free < MAX_STRTAB) {
-	    result = (stringbuf + next_free - 1);
+    if (stringbuf != NULL) {
+	if (!VALID_STRING(string))
+	    string = "";
+	len = strlen(string) + 1;
+
+	if (len == 1 && next_free != 0) {
+	    /*
+	     * Cheat a little by making an empty string point to the end of the
+	     * previous string.
+	     */
+	    if (next_free < MAX_STRTAB) {
+		result = (stringbuf + next_free - 1);
+	    }
+	} else if (next_free + len < MAX_STRTAB) {
+	    _nc_STRCPY(&stringbuf[next_free], string, MAX_STRTAB);
+	    DEBUG(7, ("Saved string %s", _nc_visbuf(string)));
+	    DEBUG(7, ("at location %d", (int) next_free));
+	    next_free += len;
+	    result = (stringbuf + old_next_free);
+	} else {
+	    _nc_warning("Too much data, some is lost: %s", string);
 	}
-    } else if (next_free + len < MAX_STRTAB) {
-	_nc_STRCPY(&stringbuf[next_free], string, MAX_STRTAB);
-	DEBUG(7, ("Saved string %s", _nc_visbuf(string)));
-	DEBUG(7, ("at location %d", (int) next_free));
-	next_free += len;
-	result = (stringbuf + old_next_free);
-    } else {
-	_nc_warning("Too much data, some is lost: %s", string);
     }
     return result;
 }
@@ -130,9 +134,14 @@
     int offsets[MAX_ENTRY_SIZE / sizeof(short)];
     int useoffsets[MAX_USES];
     unsigned i, n;
-    unsigned nuses = ep->nuses;
-    TERMTYPE2 *tp = &(ep->tterm);
+    unsigned nuses;
+    TERMTYPE2 *tp;
+
+    if (ep == NULL || stringbuf == NULL)
+	_nc_err_abort("_nc_wrap_entry called without initialization");
 
+    nuses = ep->nuses;
+    tp = &(ep->tterm);
     if (copy_strings) {
 	next_free = 0;		/* clear static storage */
 
@@ -294,7 +303,7 @@
 NCURSES_EXPORT(void)
 _nc_alloc_entry_leaks(void)
 {
-    if (stringbuf != 0) {
+    if (stringbuf != NULL) {
 	FreeAndNull(stringbuf);
     }
     next_free = 0;
Index: ncurses/tinfo/write_entry.c
Prereq:  1.118 
--- ncurses-6.3-20220219+/ncurses/tinfo/write_entry.c	2021-08-15 20:07:11.000000000 +0000
+++ ncurses-6.3-20220226/ncurses/tinfo/write_entry.c	2022-02-26 20:59:58.000000000 +0000
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright 2018-2020,2021 Thomas E. Dickey                                *
+ * Copyright 2018-2021,2022 Thomas E. Dickey                                *
  * Copyright 1998-2016,2017 Free Software Foundation, Inc.                  *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
@@ -51,7 +51,7 @@
 #define TRACE_NUM(n)		/* nothing */
 #endif
 
-MODULE_ID("$Id: write_entry.c,v 1.118 2021/08/15 20:07:11 tom Exp $")
+MODULE_ID("$Id: write_entry.c,v 1.119 2022/02/26 20:59:58 tom Exp $")
 
 static int total_written;
 static int total_parts;
@@ -145,7 +145,7 @@
 	    rc = 0;
 	}
     } else {
-	if (strlen(top) + strlen(src) + 2 <= limit) {
+	if ((strlen(top) + strlen(src) + 6) <= limit) {
 	    _nc_SPRINTF(dst, _nc_SLIMIT(limit) "%s/%s", top, src);
 	    rc = 0;
 	}
Index: package/debian-mingw/changelog
--- ncurses-6.3-20220219+/package/debian-mingw/changelog	2022-02-19 12:13:47.000000000 +0000
+++ ncurses-6.3-20220226/package/debian-mingw/changelog	2022-02-26 12:23:15.000000000 +0000
@@ -1,8 +1,8 @@
-ncurses6 (6.3+20220219) unstable; urgency=low
+ncurses6 (6.3+20220226) unstable; urgency=low
 
   * latest weekly patch
 
- -- Thomas E. Dickey <dickey@invisible-island.net>  Sat, 19 Feb 2022 07:13:47 -0500
+ -- Thomas E. Dickey <dickey@invisible-island.net>  Sat, 26 Feb 2022 07:23:15 -0500
 
 ncurses6 (5.9-20131005) unstable; urgency=low
 
Index: package/debian-mingw64/changelog
--- ncurses-6.3-20220219+/package/debian-mingw64/changelog	2022-02-19 12:13:47.000000000 +0000
+++ ncurses-6.3-20220226/package/debian-mingw64/changelog	2022-02-26 12:23:15.000000000 +0000
@@ -1,8 +1,8 @@
-ncurses6 (6.3+20220219) unstable; urgency=low
+ncurses6 (6.3+20220226) unstable; urgency=low
 
   * latest weekly patch
 
- -- Thomas E. Dickey <dickey@invisible-island.net>  Sat, 19 Feb 2022 07:13:47 -0500
+ -- Thomas E. Dickey <dickey@invisible-island.net>  Sat, 26 Feb 2022 07:23:15 -0500
 
 ncurses6 (5.9-20131005) unstable; urgency=low
 
Index: package/debian/changelog
--- ncurses-6.3-20220219+/package/debian/changelog	2022-02-19 12:13:47.000000000 +0000
+++ ncurses-6.3-20220226/package/debian/changelog	2022-02-26 12:23:15.000000000 +0000
@@ -1,8 +1,8 @@
-ncurses6 (6.3+20220219) unstable; urgency=low
+ncurses6 (6.3+20220226) unstable; urgency=low
 
   * latest weekly patch
 
- -- Thomas E. Dickey <dickey@invisible-island.net>  Sat, 19 Feb 2022 07:13:47 -0500
+ -- Thomas E. Dickey <dickey@invisible-island.net>  Sat, 26 Feb 2022 07:23:15 -0500
 
 ncurses6 (5.9-20120608) unstable; urgency=low
 
Index: package/mingw-ncurses.nsi
Prereq:  1.507 
--- ncurses-6.3-20220219+/package/mingw-ncurses.nsi	2022-02-19 12:13:47.000000000 +0000
+++ ncurses-6.3-20220226/package/mingw-ncurses.nsi	2022-02-26 12:23:15.000000000 +0000
@@ -1,4 +1,4 @@
-; $Id: mingw-ncurses.nsi,v 1.507 2022/02/19 12:13:47 tom Exp $
+; $Id: mingw-ncurses.nsi,v 1.508 2022/02/26 12:23:15 tom Exp $
 
 ; TODO add examples
 ; TODO bump ABI to 6
@@ -10,7 +10,7 @@
 !define VERSION_MAJOR "6"
 !define VERSION_MINOR "3"
 !define VERSION_YYYY  "2022"
-!define VERSION_MMDD  "0219"
+!define VERSION_MMDD  "0226"
 !define VERSION_PATCH ${VERSION_YYYY}${VERSION_MMDD}
 
 !define MY_ABI   "5"
Index: package/mingw-ncurses.spec
--- ncurses-6.3-20220219+/package/mingw-ncurses.spec	2022-02-19 12:13:47.000000000 +0000
+++ ncurses-6.3-20220226/package/mingw-ncurses.spec	2022-02-26 12:23:15.000000000 +0000
@@ -3,7 +3,7 @@
 Summary: shared libraries for terminal handling
 Name: mingw32-ncurses6
 Version: 6.3
-Release: 20220219
+Release: 20220226
 License: X11
 Group: Development/Libraries
 Source: ncurses-%{version}-%{release}.tgz
Index: package/ncurses.spec
--- ncurses-6.3-20220219+/package/ncurses.spec	2022-02-19 12:13:47.000000000 +0000
+++ ncurses-6.3-20220226/package/ncurses.spec	2022-02-26 12:23:15.000000000 +0000
@@ -1,7 +1,7 @@
 Summary: shared libraries for terminal handling
 Name: ncurses6
 Version: 6.3
-Release: 20220219
+Release: 20220226
 License: X11
 Group: Development/Libraries
 Source: ncurses-%{version}-%{release}.tgz
Index: package/ncursest.spec
--- ncurses-6.3-20220219+/package/ncursest.spec	2022-02-19 12:13:47.000000000 +0000
+++ ncurses-6.3-20220226/package/ncursest.spec	2022-02-26 12:23:15.000000000 +0000
@@ -1,7 +1,7 @@
 Summary: Curses library with POSIX thread support.
 Name: ncursest6
 Version: 6.3
-Release: 20220219
+Release: 20220226
 License: X11
 Group: Development/Libraries
 Source: ncurses-%{version}-%{release}.tgz
Index: progs/infocmp.c
Prereq:  1.151 
--- ncurses-6.3-20220219+/progs/infocmp.c	2021-06-17 21:11:08.000000000 +0000
+++ ncurses-6.3-20220226/progs/infocmp.c	2022-02-26 23:25:55.000000000 +0000
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright 2020,2021 Thomas E. Dickey                                     *
+ * Copyright 2020-2021,2022 Thomas E. Dickey                                *
  * Copyright 1998-2016,2017 Free Software Foundation, Inc.                  *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
@@ -43,7 +43,7 @@
 
 #include <dump_entry.h>
 
-MODULE_ID("$Id: infocmp.c,v 1.151 2021/06/17 21:11:08 tom Exp $")
+MODULE_ID("$Id: infocmp.c,v 1.152 2022/02/26 23:25:55 tom Exp $")
 
 #define MAX_STRING	1024	/* maximum formatted string */
 
@@ -125,16 +125,20 @@
 }
 
 static char *
-canonical_name(char *ptr, char *buf)
+canonical_name(char *source, char *target)
 /* extract the terminal type's primary name */
 {
-    char *bp;
+    int limit = NAMESIZE;
 
-    _nc_STRCPY(buf, ptr, NAMESIZE);
-    if ((bp = strchr(buf, '|')) != 0)
-	*bp = '\0';
+    while (--limit > 0) {
+	char ch = *source++;
+	if (ch == '|')
+	    break;
+	*target++ = ch;
+    }
+    *target = '\0';
 
-    return (buf);
+    return (target);
 }
 
 static bool
Index: progs/tabs.c
Prereq:  1.50 
--- ncurses-6.3-20220219+/progs/tabs.c	2021-10-10 00:54:41.000000000 +0000
+++ ncurses-6.3-20220226/progs/tabs.c	2022-02-26 22:44:44.000000000 +0000
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright 2020,2021 Thomas E. Dickey                                     *
+ * Copyright 2020-2021,2022 Thomas E. Dickey                                *
  * Copyright 2008-2016,2017 Free Software Foundation, Inc.                  *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
@@ -39,7 +39,7 @@
 #include <progs.priv.h>
 #include <tty_settings.h>
 
-MODULE_ID("$Id: tabs.c,v 1.50 2021/10/10 00:54:41 tom Exp $")
+MODULE_ID("$Id: tabs.c,v 1.51 2022/02/26 22:44:44 tom Exp $")
 
 static GCC_NORETURN void usage(void);
 
@@ -128,7 +128,7 @@
     int prior = 0;
     int ch;
 
-    if (result == 0)
+    if (result == NULL)
 	failed("decode_tabs");
 
     if (margin < 0)
@@ -138,6 +138,8 @@
 	if (isdigit(UChar(ch))) {
 	    value *= 10;
 	    value += (ch - '0');
+	    if (value > max_cols)
+		value = max_cols;
 	} else if (ch == ',') {
 	    result[n] = value + prior + margin;
 	    if (n > 0 && result[n] <= result[n - 1]) {
Index: progs/tput.c
Prereq:  1.97 
--- ncurses-6.3-20220219+/progs/tput.c	2021-10-02 18:09:23.000000000 +0000
+++ ncurses-6.3-20220226/progs/tput.c	2022-02-26 23:19:31.000000000 +0000
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright 2018-2020,2021 Thomas E. Dickey                                *
+ * Copyright 2018-2021,2022 Thomas E. Dickey                                *
  * Copyright 1998-2016,2017 Free Software Foundation, Inc.                  *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
@@ -47,7 +47,7 @@
 #include <transform.h>
 #include <tty_settings.h>
 
-MODULE_ID("$Id: tput.c,v 1.97 2021/10/02 18:09:23 tom Exp $")
+MODULE_ID("$Id: tput.c,v 1.99 2022/02/26 23:19:31 tom Exp $")
 
 #define PUTS(s)		fputs(s, stdout)
 
@@ -160,7 +160,7 @@
     name = check_aliases(argv[0], FALSE);
     *used = 1;
     if (is_reset || is_init) {
-	TTY oldmode;
+	TTY oldmode = *settings;
 
 	int terasechar = -1;	/* new erase character */
 	int intrchar = -1;	/* new interrupt character */
@@ -180,6 +180,7 @@
 #endif
 	set_control_chars(settings, terasechar, intrchar, tkillchar);
 	set_conversions(settings);
+
 	if (send_init_strings(fd, &oldmode)) {
 	    reset_flush();
 	}
@@ -336,6 +337,7 @@
     int result = 0;
     int fd;
     int used;
+    TTY old_settings;
     TTY tty_settings;
     bool opt_x = FALSE;		/* clear scrollback if possible */
     bool is_alias;
@@ -391,6 +393,7 @@
 	quit(ErrUsage, "No value for $TERM and no -T specified");
 
     fd = save_tty_settings(&tty_settings, need_tty);
+    old_settings = tty_settings;
 
     if (setupterm(term, fd, &errret) != OK && errret <= 0)
 	quit(ErrTermType, "unknown terminal \"%s\"", term);
@@ -400,6 +403,7 @@
 	if ((argc <= 0) && !is_alias)
 	    usage(NULL);
 	while (argc > 0) {
+	    tty_settings = old_settings;
 	    code = tput_cmd(fd, &tty_settings, opt_x, argc, argv, &used);
 	    if (code != 0)
 		break;
@@ -433,7 +437,9 @@
 
 	argnow = argvec;
 	while (argnum > 0) {
-	    int code = tput_cmd(fd, &tty_settings, opt_x, argnum, argnow, &used);
+	    int code;
+	    tty_settings = old_settings;
+	    code = tput_cmd(fd, &tty_settings, opt_x, argnum, argnow, &used);
 	    if (code != 0) {
 		if (result == 0)
 		    result = ErrSystem(0);	/* will return value >4 */
Index: test/ncurses.c
Prereq:  1.527 
--- ncurses-6.3-20220219+/test/ncurses.c	2021-09-04 10:31:03.000000000 +0000
+++ ncurses-6.3-20220226/test/ncurses.c	2022-02-26 22:41:02.000000000 +0000
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright 2018-2020,2021 Thomas E. Dickey                                *
+ * Copyright 2018-2021,2022 Thomas E. Dickey                                *
  * Copyright 1998-2016,2017 Free Software Foundation, Inc.                  *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
@@ -41,7 +41,7 @@
    Author: Eric S. Raymond <esr@snark.thyrsus.com> 1993
            Thomas E. Dickey (beginning revision 1.27 in 1996).
 
-$Id: ncurses.c,v 1.527 2021/09/04 10:31:03 tom Exp $
+$Id: ncurses.c,v 1.528 2022/02/26 22:41:02 tom Exp $
 
 ***************************************************************************/
 
@@ -2885,6 +2885,10 @@
 	    while (fgets(buffer, sizeof(buffer), fp) != 0) {
 		if (sscanf(buffer, "scale:%d", &c) == 1) {
 		    scale = c;
+		    if (scale < 100)
+			scale = 100;
+		    if (scale > 1000)
+			scale = 1000;
 		} else if (sscanf(buffer, "%d:%d %d %d",
 				  &c,
 				  &red,