[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] pkl: Fix bug of handling %% in format strings
From: |
Mohammad-Reza Nabipoor |
Subject: |
Re: [PATCH] pkl: Fix bug of handling %% in format strings |
Date: |
Tue, 8 Mar 2022 16:16:56 +0330 |
ping
On Sat, Feb 26, 2022 at 02:56:47AM +0330, Mohammad-Reza Nabipoor wrote:
> 2022-02-26 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
>
> * libpoke/pkl-trans.c (pkl_trans1_ps_format): Fix format string
> arg suffix when there's a %%.
> * testsuite/poke.pkl/format-40.pk: New test.
> * testsuite/poke.pkl/format-41.pk: Likewise.
> * testsuite/poke.pkl/format-42.pk: Likewise.
> * testsuite/Makefile.am (EXTRA_DIST): Update.
> ---
> ChangeLog | 9 +++++++++
> libpoke/pkl-trans.c | 12 +++++++++++-
> testsuite/Makefile.am | 3 +++
> testsuite/poke.pkl/format-40.pk | 5 +++++
> testsuite/poke.pkl/format-41.pk | 5 +++++
> testsuite/poke.pkl/format-42.pk | 5 +++++
> 6 files changed, 38 insertions(+), 1 deletion(-)
> create mode 100644 testsuite/poke.pkl/format-40.pk
> create mode 100644 testsuite/poke.pkl/format-41.pk
> create mode 100644 testsuite/poke.pkl/format-42.pk
>
> diff --git a/ChangeLog b/ChangeLog
> index 7ecaa488..d472da8d 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,12 @@
> +2022-02-26 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
> +
> + * libpoke/pkl-trans.c (pkl_trans1_ps_format): Fix format string
> + arg suffix when there's a %%.
> + * testsuite/poke.pkl/format-40.pk: New test.
> + * testsuite/poke.pkl/format-41.pk: Likewise.
> + * testsuite/poke.pkl/format-42.pk: Likewise.
> + * testsuite/Makefile.am (EXTRA_DIST): Update.
> +
> 2022-02-24 Jose E. Marchesi <jemarch@gnu.org>
>
> * maps/Makefile.am: Revert last change.
> diff --git a/libpoke/pkl-trans.c b/libpoke/pkl-trans.c
> index eb09c351..91d30a14 100644
> --- a/libpoke/pkl-trans.c
> +++ b/libpoke/pkl-trans.c
> @@ -977,7 +977,17 @@ PKL_PHASE_BEGIN_HANDLER (pkl_trans1_ps_format)
> if (*p != '\0' && *p != '%')
> {
> char *end = strchrnul (p, '%');
> - PKL_AST_FORMAT_ARG_SUFFIX (arg) = strndup (p, end - p);
> + if (PKL_AST_FORMAT_ARG_SUFFIX (arg))
> + {
> + char* s = NULL;
> +
> + if (asprintf(&s, "%s%.*s", PKL_AST_FORMAT_ARG_SUFFIX (arg),
> + (int)(end - p), p) == -1)
> + PKL_ICE (PKL_AST_LOC (format), _("out of memory"));
> + PKL_AST_FORMAT_ARG_SUFFIX (arg) = s;
> + }
> + else
> + PKL_AST_FORMAT_ARG_SUFFIX (arg) = strndup (p, end - p);
> if (!PKL_AST_FORMAT_ARG_SUFFIX (arg))
> PKL_ICE (PKL_AST_LOC (format), _("out of memory"));
> p = end;
> diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
> index cc6c1777..5be6b388 100644
> --- a/testsuite/Makefile.am
> +++ b/testsuite/Makefile.am
> @@ -1243,6 +1243,9 @@ EXTRA_DIST = \
> poke.pkl/format-37.pk \
> poke.pkl/format-38.pk \
> poke.pkl/format-39.pk \
> + poke.pkl/format-40.pk \
> + poke.pkl/format-41.pk \
> + poke.pkl/format-42.pk \
> poke.pkl/format-diag-1.pk \
> poke.pkl/formfeedchar.pk \
> poke.pkl/fun-types-1.pk \
> diff --git a/testsuite/poke.pkl/format-40.pk b/testsuite/poke.pkl/format-40.pk
> new file mode 100644
> index 00000000..079c2304
> --- /dev/null
> +++ b/testsuite/poke.pkl/format-40.pk
> @@ -0,0 +1,5 @@
> +/* { dg-do run } */
> +
> +/* { dg-command {.set obase 10} } */
> +/* { dg-command {format("%%v")} } */
> +/* { dg-output {"%v"} } */
> diff --git a/testsuite/poke.pkl/format-41.pk b/testsuite/poke.pkl/format-41.pk
> new file mode 100644
> index 00000000..85d72a5e
> --- /dev/null
> +++ b/testsuite/poke.pkl/format-41.pk
> @@ -0,0 +1,5 @@
> +/* { dg-do run } */
> +
> +/* { dg-command {.set obase 10} } */
> +/* { dg-command {format("v%%j")} } */
> +/* { dg-output {"v%j"} } */
> diff --git a/testsuite/poke.pkl/format-42.pk b/testsuite/poke.pkl/format-42.pk
> new file mode 100644
> index 00000000..2a535a59
> --- /dev/null
> +++ b/testsuite/poke.pkl/format-42.pk
> @@ -0,0 +1,5 @@
> +/* { dg-do run } */
> +
> +/* { dg-command {.set obase 10} } */
> +/* { dg-command {format("v%%%%j%%abc%%")} } */
> +/* { dg-output {"v%%j%abc%"} } */
> --
> 2.35.1
>
>
>
- Re: [PATCH] pkl: Fix bug of handling %% in format strings,
Mohammad-Reza Nabipoor <=