c
#include <limits> // For std::numeric_limits 

// ... other code ... 

if (msg->pos + 4 > smh->submessageLength) {
    // Handle the error (log, throw exception, etc.) 
    // ...
} else {
    payload_size = smh->submessageLength - (msg->pos + 4); 
}
