| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: vis.c,v 1.73 2017/04/23 01:58:48 christos Exp $ */ | | 1 | /* $NetBSD: vis.c,v 1.74 2017/11/27 16:37:21 christos Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1989, 1993 | | 4 | * Copyright (c) 1989, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -47,27 +47,27 @@ | | | @@ -47,27 +47,27 @@ |
47 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 47 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
48 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 48 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
49 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 49 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
50 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 50 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
51 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 51 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
52 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 52 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
53 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 53 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
54 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 54 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
55 | * POSSIBILITY OF SUCH DAMAGE. | | 55 | * POSSIBILITY OF SUCH DAMAGE. |
56 | */ | | 56 | */ |
57 | | | 57 | |
58 | #include <sys/cdefs.h> | | 58 | #include <sys/cdefs.h> |
59 | #if defined(LIBC_SCCS) && !defined(lint) | | 59 | #if defined(LIBC_SCCS) && !defined(lint) |
60 | __RCSID("$NetBSD: vis.c,v 1.73 2017/04/23 01:58:48 christos Exp $"); | | 60 | __RCSID("$NetBSD: vis.c,v 1.74 2017/11/27 16:37:21 christos Exp $"); |
61 | #endif /* LIBC_SCCS and not lint */ | | 61 | #endif /* LIBC_SCCS and not lint */ |
62 | #ifdef __FBSDID | | 62 | #ifdef __FBSDID |
63 | __FBSDID("$FreeBSD$"); | | 63 | __FBSDID("$FreeBSD$"); |
64 | #define _DIAGASSERT(x) assert(x) | | 64 | #define _DIAGASSERT(x) assert(x) |
65 | #endif | | 65 | #endif |
66 | | | 66 | |
67 | #include "namespace.h" | | 67 | #include "namespace.h" |
68 | #include <sys/types.h> | | 68 | #include <sys/types.h> |
69 | #include <sys/param.h> | | 69 | #include <sys/param.h> |
70 | | | 70 | |
71 | #include <assert.h> | | 71 | #include <assert.h> |
72 | #include <vis.h> | | 72 | #include <vis.h> |
73 | #include <errno.h> | | 73 | #include <errno.h> |
| @@ -422,30 +422,30 @@ istrsenvisx(char **mbdstp, size_t *dlen, | | | @@ -422,30 +422,30 @@ istrsenvisx(char **mbdstp, size_t *dlen, |
422 | * | | 422 | * |
423 | * The vis conversion will be done using the wide char | | 423 | * The vis conversion will be done using the wide char |
424 | * wchar_t string. | | 424 | * wchar_t string. |
425 | * | | 425 | * |
426 | * This will then be converted back to a multibyte string to | | 426 | * This will then be converted back to a multibyte string to |
427 | * return to the caller. | | 427 | * return to the caller. |
428 | */ | | 428 | */ |
429 | | | 429 | |
430 | /* Allocate space for the wide char strings */ | | 430 | /* Allocate space for the wide char strings */ |
431 | psrc = pdst = extra = NULL; | | 431 | psrc = pdst = extra = NULL; |
432 | mdst = NULL; | | 432 | mdst = NULL; |
433 | if ((psrc = calloc(mbslength + 1, sizeof(*psrc))) == NULL) | | 433 | if ((psrc = calloc(mbslength + 1, sizeof(*psrc))) == NULL) |
434 | return -1; | | 434 | return -1; |
435 | if ((pdst = calloc((4 * mbslength) + 1, sizeof(*pdst))) == NULL) | | 435 | if ((pdst = calloc((16 * mbslength) + 1, sizeof(*pdst))) == NULL) |
436 | goto out; | | 436 | goto out; |
437 | if (*mbdstp == NULL) { | | 437 | if (*mbdstp == NULL) { |
438 | if ((mdst = calloc((4 * mbslength) + 1, sizeof(*mdst))) == NULL) | | 438 | if ((mdst = calloc((16 * mbslength) + 1, sizeof(*mdst))) == NULL) |
439 | goto out; | | 439 | goto out; |
440 | *mbdstp = mdst; | | 440 | *mbdstp = mdst; |
441 | } | | 441 | } |
442 | | | 442 | |
443 | mbdst = *mbdstp; | | 443 | mbdst = *mbdstp; |
444 | dst = pdst; | | 444 | dst = pdst; |
445 | src = psrc; | | 445 | src = psrc; |
446 | | | 446 | |
447 | if (flags & VIS_NOLOCALE) { | | 447 | if (flags & VIS_NOLOCALE) { |
448 | /* Do one byte at a time conversion */ | | 448 | /* Do one byte at a time conversion */ |
449 | cerr = 1; | | 449 | cerr = 1; |
450 | } else { | | 450 | } else { |
451 | /* Use caller's multibyte conversion error flag. */ | | 451 | /* Use caller's multibyte conversion error flag. */ |
| @@ -458,32 +458,33 @@ istrsenvisx(char **mbdstp, size_t *dlen, | | | @@ -458,32 +458,33 @@ istrsenvisx(char **mbdstp, size_t *dlen, |
458 | * stop at NULs because we may be processing a block of data | | 458 | * stop at NULs because we may be processing a block of data |
459 | * that includes NULs. | | 459 | * that includes NULs. |
460 | */ | | 460 | */ |
461 | while (mbslength > 0) { | | 461 | while (mbslength > 0) { |
462 | /* Convert one multibyte character to wchar_t. */ | | 462 | /* Convert one multibyte character to wchar_t. */ |
463 | if (!cerr) | | 463 | if (!cerr) |
464 | clen = mbtowc(src, mbsrc, MB_LEN_MAX); | | 464 | clen = mbtowc(src, mbsrc, MB_LEN_MAX); |
465 | if (cerr || clen < 0) { | | 465 | if (cerr || clen < 0) { |
466 | /* Conversion error, process as a byte instead. */ | | 466 | /* Conversion error, process as a byte instead. */ |
467 | *src = (wint_t)(u_char)*mbsrc; | | 467 | *src = (wint_t)(u_char)*mbsrc; |
468 | clen = 1; | | 468 | clen = 1; |
469 | cerr = 1; | | 469 | cerr = 1; |
470 | } | | 470 | } |
471 | if (clen == 0) | | 471 | if (clen == 0) { |
472 | /* | | 472 | /* |
473 | * NUL in input gives 0 return value. process | | 473 | * NUL in input gives 0 return value. process |
474 | * as single NUL byte and keep going. | | 474 | * as single NUL byte and keep going. |
475 | */ | | 475 | */ |
476 | clen = 1; | | 476 | clen = 1; |
| | | 477 | } |
477 | /* Advance buffer character pointer. */ | | 478 | /* Advance buffer character pointer. */ |
478 | src++; | | 479 | src++; |
479 | /* Advance input pointer by number of bytes read. */ | | 480 | /* Advance input pointer by number of bytes read. */ |
480 | mbsrc += clen; | | 481 | mbsrc += clen; |
481 | /* Decrement input byte count. */ | | 482 | /* Decrement input byte count. */ |
482 | mbslength -= clen; | | 483 | mbslength -= clen; |
483 | } | | 484 | } |
484 | len = src - psrc; | | 485 | len = src - psrc; |
485 | src = psrc; | | 486 | src = psrc; |
486 | | | 487 | |
487 | /* | | 488 | /* |
488 | * In the single character input case, we will have actually | | 489 | * In the single character input case, we will have actually |
489 | * processed two characters, c and nextc. Reset len back to | | 490 | * processed two characters, c and nextc. Reset len back to |