Skip to content

Commit 8a8f553

Browse files
committed
Remove trailing zeros from the output of BytesUtils::formatBytes
1 parent 02ae43a commit 8a8f553

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

test/libsolidity/util/BytesUtils.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ string BytesUtils::formatBytes(
263263
os << formatHexString(_bytes);
264264
break;
265265
case ABIType::String:
266-
os << formatString(_bytes);
266+
os << formatString(_bytes, _bytes.size() - countRightPaddedZeros(_bytes));
267267
break;
268268
case ABIType::Failure:
269269
break;
@@ -311,3 +311,12 @@ string BytesUtils::formatBytesRange(
311311
return os.str();
312312
}
313313

314+
size_t BytesUtils::countRightPaddedZeros(bytes const& _bytes)
315+
{
316+
return find_if(
317+
_bytes.rbegin(),
318+
_bytes.rend(),
319+
[](uint8_t b) { return b != '\0'; }
320+
) - _bytes.rbegin();
321+
}
322+

test/libsolidity/util/BytesUtils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ class BytesUtils
122122
ParameterList const& _parameters,
123123
bool _highlight
124124
);
125+
126+
/// Count the number of zeros between the last non-zero byte and the end of
127+
/// \param _bytes.
128+
static size_t countRightPaddedZeros(bytes const& _bytes);
125129
};
126130

127131
}

0 commit comments

Comments
 (0)