Commit 1047cde9 authored by Mike Frysinger's avatar Mike Frysinger Committed by Commit Bot

grit: c_format: use %o to avoid weird parsing

We're running an integer through oct() to get a string of the octal
number, which we then pass to int() to parse as a decimal number so
we can finally pass to %d to get a padded string.
  195 -> '0303' -> 303 -> '303'

This relies on the exact output format of oct() which breaks when
using Python 3 -- it outputs '0o303' which int() rejects.

We can simplify this greatly by just switching from %d to %o and
letting Python do the translation for us.

Bug: 983071
Test: `./grit/test_suite_all.py` passes
Change-Id: I9c379d0962819e69eed2890bc2369784c0a95ef3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1755384Reviewed-by: default avatarRobert Flack <flackr@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Cr-Commit-Position: refs/heads/master@{#687255}
parent 0a4457ea
...@@ -56,7 +56,7 @@ def _HexToOct(match): ...@@ -56,7 +56,7 @@ def _HexToOct(match):
result = "" result = ""
while len(hex): while len(hex):
next_num = int(hex[2:4], 16) next_num = int(hex[2:4], 16)
result += "\\" + '%03d' % int(oct(next_num), 10) result += "\\" + '%03o' % next_num
hex = hex[4:] hex = hex[4:]
return match.group("escaped_backslashes") + result return match.group("escaped_backslashes") + result
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment