Commit 18fd6fc8 authored by Ivan Egorov's avatar Ivan Egorov Committed by Facebook GitHub Bot

Add a note into constexpr_strcmp

Summary: This explains why the commonly used `int(*s1 - *s2)` was changed to a slightly less obvious alternative.

Reviewed By: yfeldblum

Differential Revision: D23537394

fbshipit-source-id: 152554bc9864cdf25c569216d21b0c04bea67e9d
parent 809c5665
...@@ -83,6 +83,7 @@ constexpr int constexpr_strcmp_internal( ...@@ -83,6 +83,7 @@ constexpr int constexpr_strcmp_internal(
while (*s1 && *s1 == *s2) { while (*s1 && *s1 == *s2) {
++s1, ++s2; ++s1, ++s2;
} }
// NOTE: `int(*s1 - *s2)` may cause signed arithmetics overflow which is UB.
return int(*s2 < *s1) - int(*s1 < *s2); return int(*s2 < *s1) - int(*s1 < *s2);
} }
......
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