aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorumarcor <unai.martinezcorral@ehu.eus>2021-08-02 02:04:17 +0200
committerumarcor <unai.martinezcorral@ehu.eus>2021-08-23 16:35:33 +0200
commitc7f774ff0ade8efe292c00dd6ceb31c42d631278 (patch)
treecc51db9007d26d9475d483ba717042ec00ffa181
parent9e612ed4cacdc6bd1e24b41747c49a3fd9b1f24e (diff)
downloadghdl-c7f774ff0ade8efe292c00dd6ceb31c42d631278.tar.gz
ghdl-c7f774ff0ade8efe292c00dd6ceb31c42d631278.tar.bz2
ghdl-c7f774ff0ade8efe292c00dd6ceb31c42d631278.zip
FIX pass the length to probably unterminated string extraction
(cherry picked from commit afee8309e4b644e0e94c1938c0f4e211ae3038fa)
-rw-r--r--pyGHDL/dom/Literal.py10
-rw-r--r--pyGHDL/libghdl/str_table.py4
2 files changed, 9 insertions, 5 deletions
diff --git a/pyGHDL/dom/Literal.py b/pyGHDL/dom/Literal.py
index 5fb31f0e7..26be52ec8 100644
--- a/pyGHDL/dom/Literal.py
+++ b/pyGHDL/dom/Literal.py
@@ -149,6 +149,10 @@ class StringLiteral(VHDLModel_StringLiteral, DOMMixin):
@classmethod
def parse(cls, literalNode: Iir) -> "StringLiteral":
- stringID = nodes.Get_String8_Id(literalNode)
- value = str_table.Get_String8_Ptr(stringID)
- return cls(literalNode, value)
+ if nodes.Get_Bit_String_Base(literalNode) is nodes.NumberBaseType.Base_None:
+ value = str_table.Get_String8_Ptr(
+ nodes.Get_String8_Id(literalNode), nodes.Get_String_Length(literalNode)
+ )
+ return cls(literalNode, value)
+ else:
+ print("[NOT IMPLEMENTED] Bit String Literal not supported yet")
diff --git a/pyGHDL/libghdl/str_table.py b/pyGHDL/libghdl/str_table.py
index 4cd138f44..f87e9db8b 100644
--- a/pyGHDL/libghdl/str_table.py
+++ b/pyGHDL/libghdl/str_table.py
@@ -48,7 +48,7 @@ def _String8_Address(Id: String8Id) -> c_char_p:
@export
-def Get_String8_Ptr(Id: String8Id) -> str:
+def Get_String8_Ptr(Id: String8Id, Length: int) -> str:
"""
Get the address of string8 ID. Note that as soon as a character is appended
(using Append_String8) or a string8 is resized (using Resize_String8), an
@@ -57,4 +57,4 @@ def Get_String8_Ptr(Id: String8Id) -> str:
:param Id: String8Id for the string to query.
:return: String8 as string.
"""
- return _String8_Address(Id).decode("utf-8")
+ return _String8_Address(Id)[:Length].decode("utf-8")