It's not an upstream code and indeed well spotted.
The proper way to handle overflow is much more complicated, AFAIR.
But maybe we can manage with:

~~~~
if (!(x > UINT_MAX - result)) {
    result += x;
}
~~~~