Codebase list mksh / d60aa3c
Merge branch 'origtgz' mirabilos authored 2 years ago mirabilos committed 2 years ago
2 changed file(s) with 9 addition(s) and 79 deletion(s). Raw diff Collapse all Expand all
0 mksh (59c-8) unstable; urgency=medium
1
2 * Fix a -Wpointer-sign in escaping code
3 * Shrink escape diff (algorithm unchanged) for easier review
4
5 -- Thorsten Glaser <tg@mirbsd.de> Mon, 31 May 2021 02:42:55 +0200
6
07 mksh (59c-7) unstable; urgency=medium
18
29 * Do not use sigsetjmp(…, 0) with klibc (cf. #988027)
5757 static void chvt(const Getopt *);
5858 #endif
5959 static unsigned int dollarqU(struct shf *, const unsigned char *);
60 #ifndef MKSH_SMALL
61 static void dollarq8(struct shf *, const unsigned char *);
62 #else
6360 #define dollarq8 dollarqU
64 #endif
6561
6662 /*XXX this should go away */
6763 static int make_path(const char *, const char *, char **, XString *, int *);
14901486 #endif
14911487
14921488 #define dollarq_Uctrl(c) !ctype(c, C_PRINT)
1493 #ifndef MKSH_SMALL
1494 #define dollarq_isctrlU(c) dollarq_Uctrl(c)
1495 #else
14961489 #define dollarq_isctrlU(c) UTFMODE ? dollarq_Uctrl(c) : dollarq_isctrl8(c)
1497 #endif
14981490
14991491 /* escape with $'...' (!MKSH_SMALL: in UTFMODE) */
15001492 static unsigned int
15081500 shf_putc('$', shf);
15091501 shf_putc('\'', shf);
15101502 while ((c = *s) != 0) {
1511 if (
1512 #ifdef MKSH_SMALL
1513 UTFMODE &&
1514 #endif
1503 if (UTFMODE &&
15151504 rtt2asc(c) >= 0xC2U && (n = utf_mbtowc(&wc,
15161505 (const char *)s)) != (size_t)-1) {
15171506 /* valid UTF-8 multibyte character > 0x7F */
15251514 * interlinear annotations, LTR/RTL mark,
15261515 * U+2028, U+2029, U+2066..U+206F, etc.
15271516 */
1528 shf_write(s, n, shf);
1517 shf_write((const char *)s, n, shf);
15291518 }
15301519 s += n;
15311520 continue;
15891578 shf_putc('\'', shf);
15901579 return (rv);
15911580 }
1592
1593 #ifndef MKSH_SMALL
1594 /* escape with $'...' outside UTFMODE */
1595 static void
1596 dollarq8(struct shf *shf, const unsigned char *s)
1597 {
1598 unsigned char c;
1599
1600 shf_putc('$', shf);
1601 shf_putc('\'', shf);
1602 while ((c = *s++) != 0) {
1603 /* single octet */
1604 switch (c) {
1605 /* see unbksl() in this file for comments */
1606 case KSH_BEL:
1607 c = 'a';
1608 if (0)
1609 /* FALLTHROUGH */
1610 case '\b':
1611 c = 'b';
1612 if (0)
1613 /* FALLTHROUGH */
1614 case '\f':
1615 c = 'f';
1616 if (0)
1617 /* FALLTHROUGH */
1618 case '\n':
1619 c = 'n';
1620 if (0)
1621 /* FALLTHROUGH */
1622 case '\r':
1623 c = 'r';
1624 if (0)
1625 /* FALLTHROUGH */
1626 case '\t':
1627 c = 't';
1628 if (0)
1629 /* FALLTHROUGH */
1630 case KSH_VTAB:
1631 c = 'v';
1632 if (0)
1633 /* FALLTHROUGH */
1634 case KSH_ESC:
1635 /* take E not e because \e is \ in *roff */
1636 c = 'E';
1637 /* FALLTHROUGH */
1638 case '\\':
1639 shf_putc('\\', shf);
1640
1641 if (0)
1642 /* FALLTHROUGH */
1643 default:
1644 if (dollarq_isctrl8(c)) {
1645 /* FALLTHROUGH */
1646 case '\'':
1647 shf_fprintf(shf, "\\%03o", c);
1648 break;
1649 }
1650
1651 shf_putc(c, shf);
1652 break;
1653 }
1654 }
1655 shf_putc('\'', shf);
1656 }
1657 #endif
16581581
16591582 /*
16601583 * Print things in columns and rows - func() is called to format