Additional cleanup for SDL_RWprintf() (thanks @sezero!)
This commit is contained in:
@@ -518,7 +518,7 @@ extern DECLSPEC size_t SDLCALL SDL_RWwrite(SDL_RWops *context, const void *ptr,
|
|||||||
* \sa SDL_RWseek
|
* \sa SDL_RWseek
|
||||||
* \sa SDL_RWwrite
|
* \sa SDL_RWwrite
|
||||||
*/
|
*/
|
||||||
extern DECLSPEC size_t SDLCALL SDL_RWprintf(SDL_RWops *context, SDL_PRINTF_FORMAT_STRING const char *fmt, ...);
|
extern DECLSPEC size_t SDLCALL SDL_RWprintf(SDL_RWops *context, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print to an SDL_RWops data stream.
|
* Print to an SDL_RWops data stream.
|
||||||
|
|||||||
@@ -812,14 +812,17 @@ size_t SDL_RWprintf(SDL_RWops *context, SDL_PRINTF_FORMAT_STRING const char *fmt
|
|||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int size;
|
int size;
|
||||||
char *string = NULL;
|
char *string;
|
||||||
size_t bytes;
|
size_t bytes;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
size = SDL_vasprintf(&string, fmt, ap);
|
size = SDL_vasprintf(&string, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
if (size < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
bytes = SDL_RWwrite(context, string, size);
|
bytes = SDL_RWwrite(context, string, (size_t)size);
|
||||||
SDL_free(string);
|
SDL_free(string);
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
@@ -827,12 +830,15 @@ size_t SDL_RWprintf(SDL_RWops *context, SDL_PRINTF_FORMAT_STRING const char *fmt
|
|||||||
size_t SDL_RWvprintf(SDL_RWops *context, const char *fmt, va_list ap)
|
size_t SDL_RWvprintf(SDL_RWops *context, const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
int size;
|
int size;
|
||||||
char *string = NULL;
|
char *string;
|
||||||
size_t bytes;
|
size_t bytes;
|
||||||
|
|
||||||
size = SDL_vasprintf(&string, fmt, ap);
|
size = SDL_vasprintf(&string, fmt, ap);
|
||||||
|
if (size < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
bytes = SDL_RWwrite(context, string, size);
|
bytes = SDL_RWwrite(context, string, (size_t)size);
|
||||||
SDL_free(string);
|
SDL_free(string);
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user