mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-01-31 11:23:21 +00:00
Codechange: use fmt::format instead of vseprintf for midi command formatting
This commit is contained in:
parent
c8ff6a9f7c
commit
9fe853f7b5
@ -12,6 +12,7 @@
|
||||
#include "os2_m.h"
|
||||
#include "midifile.hpp"
|
||||
#include "../base_media_base.h"
|
||||
#include "../3rdparty/fmt/format.h"
|
||||
|
||||
#define INCL_DOS
|
||||
#define INCL_OS2MM
|
||||
@ -36,14 +37,9 @@
|
||||
* @param cmd The command to send.
|
||||
* @return The result of sending it.
|
||||
*/
|
||||
static long CDECL MidiSendCommand(const char *cmd, ...)
|
||||
static long CDECL MidiSendCommand(const std::string_view cmd)
|
||||
{
|
||||
va_list va;
|
||||
char buf[512];
|
||||
va_start(va, cmd);
|
||||
vseprintf(buf, lastof(buf), cmd, va);
|
||||
va_end(va);
|
||||
return mciSendString(buf, nullptr, 0, nullptr, 0);
|
||||
return mciSendString(cmd.data(), nullptr, 0, nullptr, 0);
|
||||
}
|
||||
|
||||
/** OS/2's music player's factory. */
|
||||
@ -56,7 +52,7 @@ void MusicDriver_OS2::PlaySong(const MusicSongInfo &song)
|
||||
MidiSendCommand("close all");
|
||||
if (filename.empty()) return;
|
||||
|
||||
if (MidiSendCommand("open %s type sequencer alias song", filename.c_str()) != 0) {
|
||||
if (MidiSendCommand(fmt::format("open {} type sequencer alias song", filename)) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@
|
||||
#define sprintf SAFEGUARD_DO_NOT_USE_THIS_METHOD
|
||||
#define snprintf SAFEGUARD_DO_NOT_USE_THIS_METHOD
|
||||
|
||||
/* Use vseprintf instead. */
|
||||
/* Use fmt::format instead. */
|
||||
#define vsprintf SAFEGUARD_DO_NOT_USE_THIS_METHOD
|
||||
#define vsnprintf SAFEGUARD_DO_NOT_USE_THIS_METHOD
|
||||
|
||||
|
@ -50,23 +50,6 @@
|
||||
#include "safeguards.h"
|
||||
#undef vsnprintf
|
||||
|
||||
/**
|
||||
* Safer implementation of vsnprintf; same as vsnprintf except:
|
||||
* - last instead of size, i.e. replace sizeof with lastof.
|
||||
* - return gives the amount of characters added, not what it would add.
|
||||
* @param str buffer to write to up to last
|
||||
* @param last last character we may write to
|
||||
* @param format the formatting (see snprintf)
|
||||
* @param ap the list of arguments for the format
|
||||
* @return the number of added characters
|
||||
*/
|
||||
int CDECL vseprintf(char *str, const char *last, const char *format, va_list ap)
|
||||
{
|
||||
ptrdiff_t diff = last - str;
|
||||
if (diff < 0) return 0;
|
||||
return std::min(static_cast<int>(diff), vsnprintf(str, diff + 1, format, ap));
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends characters from one string to another.
|
||||
*
|
||||
@ -536,10 +519,14 @@ int CDECL vsnprintf(char *str, size_t size, const char *format, va_list ap)
|
||||
*/
|
||||
int CDECL seprintf(char *str, const char *last, const char *format, ...)
|
||||
{
|
||||
ptrdiff_t diff = last - str;
|
||||
if (diff < 0) return 0;
|
||||
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
int ret = vseprintf(str, last, format, ap);
|
||||
int ret = std::min(static_cast<int>(diff), vsnprintf(str, diff + 1, format, ap));
|
||||
|
||||
va_end(ap);
|
||||
return ret;
|
||||
}
|
||||
|
@ -36,7 +36,6 @@ char *strecpy(char *dst, const char *src, const char *last) NOACCESS(3);
|
||||
char *stredup(const char *src, const char *last = nullptr) NOACCESS(2);
|
||||
|
||||
int CDECL seprintf(char *str, const char *last, const char *format, ...) WARN_FORMAT(3, 4) NOACCESS(2);
|
||||
int CDECL vseprintf(char *str, const char *last, const char *format, va_list ap) WARN_FORMAT(3, 0) NOACCESS(2);
|
||||
|
||||
std::string FormatArrayAsHex(span<const byte> data);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user