[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/2] pvm: wrap string literals in named global variables
From: |
Mohammad-Reza Nabipoor |
Subject: |
[PATCH 1/2] pvm: wrap string literals in named global variables |
Date: |
Wed, 11 Jan 2023 07:38:15 +0100 |
Accessing any non-wrapped global object/function will lead to UB
in Jitter. This commit wraps globals for `formatf{32,64}`
instructions.
2023-01-11 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
* libpoke/pvm.jitter (wrapped-globals): Add
pvm_literal_formatf_{fmt,styles} to the list.
(pvm_literal_formatf_fmt): Define global variable for wrapping
format string in `formatf{32,64}' (we cannot directly use string
literals in advanced modes).
(pvm_literal_formatf_styles): Likewise.
(FORMATF): Use new wrapped globals. Remove % operator.
---
ChangeLog | 10 ++++++++++
libpoke/pvm.jitter | 9 ++++++---
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index e1762b12..e9a306f5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2023-01-11 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
+
+ * libpoke/pvm.jitter (wrapped-globals): Add
+ pvm_literal_formatf_{fmt,styles} to the list.
+ (pvm_literal_formatf_fmt): Define global variable for wrapping
+ format string in `formatf{32,64}' (we cannot directly use string
+ literals in advanced modes).
+ (pvm_literal_formatf_styles): Likewise.
+ (FORMATF): Use new wrapped globals. Remove % operator.
+
2023-01-11 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
* libpoke/pvm.jitter (formatf32): Add literal parameter to the
diff --git a/libpoke/pvm.jitter b/libpoke/pvm.jitter
index e59490e0..0e547786 100644
--- a/libpoke/pvm.jitter
+++ b/libpoke/pvm.jitter
@@ -163,6 +163,8 @@ wrapped-globals
pvm_literal_eindex
pvm_literal_notmappable
pvm_literal_newline
+ pvm_literal_formatf_fmt
+ pvm_literal_formatf_styles
libpoke_term_if
pvm_exception_names
end
@@ -878,7 +880,6 @@ late-header-c
#define FORMATF(RESULT,NUM,PREC,STYLE,TYPEF) \
do \
{ \
- static const char STYLES[] = { 'f', 'e', 'g' }; \
TYPEF x; \
int n; \
char fmt[16]; \
@@ -887,8 +888,8 @@ late-header-c
PVM_ASSERT ((STYLE) < 3); \
\
memcpy (&x, &(NUM), sizeof (NUM)); \
- n = snprintf (fmt, sizeof (fmt), "%%.%u%c", (unsigned)(PREC), \
- STYLES[(STYLE) % 3]); \
+ n = snprintf (fmt, sizeof (fmt), pvm_literal_formatf_fmt, \
+ (unsigned)(PREC), pvm_literal_formatf_styles[(STYLE)]); \
if (n == -1) \
PVM_RAISE_DFL (PVM_E_CONV); \
n = asprintf (&(RESULT), fmt, x); \
@@ -931,6 +932,8 @@ late-c
static const char *pvm_literal_eindex = "invalid index in ains";
static const char *pvm_literal_notmappable = "not mappable value";
static const char *pvm_literal_newline = "\n";
+ static const char *pvm_literal_formatf_fmt = "%%.%u%c";
+ static const char pvm_literal_formatf_styles[3] = { 'f', 'e', 'g' };
#define E(key) [PVM_E_##key] = PVM_E_##key##_NAME,
static const char *pvm_exception_names[] = {
--
2.39.0
- [PATCH 1/2] pvm: wrap string literals in named global variables,
Mohammad-Reza Nabipoor <=
Re: [PATCH 1/2] pvm: wrap string literals in named global variables, Jose E. Marchesi, 2023/01/11