Skip to content

Commit cb94b1b

Browse files
Omri Sarigkartben
authored andcommitted
scripts/logging: Add support for numbered %ll and %hh
Python does not support values of long-long (ll) or short-short (hh) in string-formatting. The current parser is correctly removing the first "h" or "l" from the format, to make it possible to correctly parse these strings when they are in the dictionary. However, the current implementation does not correctly handle the case of having a number before the "ll" or "hh" argument - which is supported by both C and Python. This commit updates the parser to correctly handle these cases, by changing the simple replace operator with a regex replace, which is able to correctly handle this case. Before this commit, the string of: "This is my long variable: %08llX" will stay the same, which will throw a ValueError when parsing this dictionary message: "ValueError: unsupported format character 'h' (0x68) at index ". After this commit, the string will be correctly fixed to "This is my long variable: %08lX" which is parsed correctly. Signed-off-by: Omri Sarig <[email protected]>
1 parent 54165f4 commit cb94b1b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

scripts/logging/dictionary/dictionary_parser/log_parser.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"""
1010

1111
import abc
12+
import re
1213

1314
from colorama import Fore
1415

@@ -36,13 +37,13 @@ def formalize_fmt_string(fmt_str):
3637

3738
for spec in ['d', 'i', 'o', 'u', 'x', 'X']:
3839
# Python doesn't support %ll for integer specifiers, so remove extra 'l'
39-
new_str = new_str.replace("%ll" + spec, "%l" + spec)
40+
new_str = re.sub(r'%(\#?\d*)ll' + spec, r'%\1l' + spec, new_str)
4041

4142
if spec in ['x', 'X']:
42-
new_str = new_str.replace("%#ll" + spec, "%#l" + spec)
43+
new_str = re.sub(r'%\#(\d*)ll' + spec, r'%#\1l' + spec, new_str)
4344

4445
# Python doesn't support %hh for integer specifiers, so remove extra 'h'
45-
new_str = new_str.replace("%hh" + spec, "%h" + spec)
46+
new_str = re.sub(r'%(\#?\d*)hh' + spec, r'%\1h' + spec, new_str)
4647

4748
# No %p for pointer either, so use %x
4849
new_str = new_str.replace("%p", "0x%x")

0 commit comments

Comments
 (0)