Commit c056a99
Strip trailing colon from convertMacToString output
Summary:
Fixes #258. MacHelpers.cpp:52
formatted each MAC byte as "{0:02x}:" unconditionally, so
convertMacToString appended a colon after every byte including the
last, producing "aa:bb:cc:dd:ee:ff:" instead of valid MAC notation
"aa:bb:cc:dd:ee:ff". Rewrote the loop to insert the separator only
between bytes (index > 0) instead of building the full string then
truncating, dropping the now-unneeded intermediate locals.
Checked every caller of convertMacToString (KatranGrpcService.cpp,
KatranServiceHandler.cpp Thrift getMac handler) through to their
consumers (katranadm CLI print, go client log line): both are
display-only, nothing parses or string-compares the trailing colon,
so blast radius is limited to the returned string's format. Updated
MacHelpersTest.cpp's 3 hardcoded assertions and the
stringToUintRoundTrip test, which previously codified the trailing
colon (and worked around it with a manual substr) as expected
behavior.
Community PR #259 proposes
the same fix via mac_string.substr(0, mac_string.size() - 1)
(build-full-then-truncate); this diff takes the equivalent
insert-separator-only approach instead to avoid the redundant
allocation and unused intermediate locals, and additionally fixes
the test fixtures the PR's description doesn't mention.
Reviewed By: tagrawal03
Differential Revision: D114403491
fbshipit-source-id: 4d2fd4a5b60121d22644e7498f4e6fc8207604341 parent dbbe81e commit c056a99
2 files changed
Lines changed: 12 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
48 | | - | |
49 | 47 | | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
54 | 53 | | |
55 | 54 | | |
56 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
79 | | - | |
80 | | - | |
| 78 | + | |
| 79 | + | |
81 | 80 | | |
82 | 81 | | |
83 | 82 | | |
84 | | - | |
85 | | - | |
86 | | - | |
| 83 | + | |
| 84 | + | |
87 | 85 | | |
88 | 86 | | |
89 | 87 | | |
0 commit comments