- removed some ZDoomd dependencies from Timidity(GUS) backend

* use std::string instead of FString
* replaced the single use of clamp with std::min/std::max.
* copied MAKE_ID macro into the source.
* use snprintf instead of mysnprintf
* use std::runtime_error instead of I_Error to abort on failed memory allocations.
This commit is contained in:
Christoph Oelckers 2019-09-24 11:07:32 +02:00
commit fea0f77905
9 changed files with 44 additions and 27 deletions

View file

@ -23,8 +23,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <exception>
#include "timidity.h"
#include "doomerrors.h"
namespace Timidity
{
@ -34,10 +35,12 @@ namespace Timidity
/* This'll allocate memory or die. */
void *safe_malloc(size_t count)
{
char buffer[80];
void *p;
if (count > (1 << 21))
{
I_Error("Timidity: Tried allocating %zu bytes. This must be a bug.", count);
snprintf(buffer, 80, "Timidity: Tried allocating %zu bytes. This must be a bug.", count);
throw std::runtime_error(buffer);
}
else if ((p = malloc(count)))
{
@ -45,7 +48,8 @@ void *safe_malloc(size_t count)
}
else
{
I_Error("Timidity: Couldn't malloc %zu bytes.", count);
snprintf(buffer, 80, "Timidity: Couldn't malloc %zu bytes.", count);
throw std::runtime_error(buffer);
}
return 0; // Unreachable.
}