Skip to content

Commit

Permalink
Better error message setting for SDLNet_GetAddressString.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Sep 26, 2023
1 parent ebe934a commit 9a4e171
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion SDL_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,19 @@ int SDLNet_GetAddressStatus(SDLNet_Address *addr)

const char *SDLNet_GetAddressString(SDLNet_Address *addr)
{
return addr ? (const char *) SDL_AtomicGetPtr((void **) &addr->human_readable) : NULL;
if (!addr) {
SDL_InvalidParamError("address");
return NULL;
}

const char *retval = (const char *) SDL_AtomicGetPtr((void **) &addr->human_readable);
if (!retval) {
const int rc = SDLNet_GetAddressStatus(addr);
if (rc != -1) { // if -1, it'll set the error message.
SDL_SetError("Address not yet resolved"); // if this resolved in a race condition, too bad, try again.
}
}
return retval;
}

int SDLNet_CompareAddresses(const SDLNet_Address *sdlneta, const SDLNet_Address *sdlnetb)
Expand Down

0 comments on commit 9a4e171

Please sign in to comment.