Skip to content

Commit

Permalink
From 272d73474da23ca7fa9024142af0a60e5fd3093c Mon Sep 17 00:00:00 2001
Browse files Browse the repository at this point in the history
From: Andrey Nazarov <[email protected]>
Date: Sun, 1 Jul 2018 19:05:11 +0300
Subject: [PATCH 170/396] Get rid of ssize_t.

This is a wrong return type for functions that return negative value on
error and byte count on success.

Functions that take a memory buffer are never passed buffers exceeding
INT_MAX bytes in size, therefore they can return a plain int.

Functions that return file sizes or positions can return values
exceeding INT_MAX, therefore they must return int64_t.
  • Loading branch information
Paril committed Dec 10, 2021
1 parent 61c1eab commit ff729e4
Show file tree
Hide file tree
Showing 28 changed files with 125 additions and 119 deletions.
2 changes: 1 addition & 1 deletion inc/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ bool CL_CheatsOK(void);
void CL_SetSky(void);

#if USE_CURL
ssize_t HTTP_FetchFile(const char *url, void **data);
int HTTP_FetchFile(const char *url, void **data);
#endif

bool CL_ForwardToServer(void);
Expand Down
16 changes: 8 additions & 8 deletions inc/common/files.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ qerror_t FS_CreatePath(char *path);

char *FS_CopyExtraInfo(const char *name, const file_info_t *info);

ssize_t FS_FOpenFile(const char *filename, qhandle_t *f, unsigned mode);
int64_t FS_FOpenFile(const char *filename, qhandle_t *f, unsigned mode);
void FS_FCloseFile(qhandle_t f);
qhandle_t FS_EasyOpenFile(char *buf, size_t size, unsigned mode,
const char *dir, const char *name, const char *ext);
Expand All @@ -134,7 +134,7 @@ qerror_t FS_FilterFile(qhandle_t f);
#define FS_FileExists(path) \
FS_FileExistsEx(path, 0)

ssize_t FS_LoadFileEx(const char *path, void **buffer, unsigned flags, memtag_t tag);
int FS_LoadFileEx(const char *path, void **buffer, unsigned flags, memtag_t tag);
// a NULL buffer will just return the file length without loading
// length < 0 indicates error

Expand All @@ -144,19 +144,19 @@ bool FS_EasyWriteFile(char *buf, size_t size, unsigned mode,
const char *dir, const char *name, const char *ext,
const void *data, size_t len);

ssize_t FS_Read(void *buffer, size_t len, qhandle_t f);
ssize_t FS_Write(const void *buffer, size_t len, qhandle_t f);
int FS_Read(void *buffer, size_t len, qhandle_t f);
int FS_Write(const void *buffer, size_t len, qhandle_t f);
// properly handles partial reads

ssize_t FS_FPrintf(qhandle_t f, const char *format, ...) q_printf(2, 3);
ssize_t FS_ReadLine(qhandle_t f, char *buffer, size_t size);
int FS_FPrintf(qhandle_t f, const char *format, ...) q_printf(2, 3);
int FS_ReadLine(qhandle_t f, char *buffer, size_t size);

void FS_Flush(qhandle_t f);

ssize_t FS_Tell(qhandle_t f);
int64_t FS_Tell(qhandle_t f);
qerror_t FS_Seek(qhandle_t f, off_t offset);

ssize_t FS_Length(qhandle_t f);
int64_t FS_Length(qhandle_t f);

bool FS_WildCmp(const char *filter, const char *string);
bool FS_ExtCmp(const char *extension, const char *string);
Expand Down
8 changes: 4 additions & 4 deletions src/client/demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Stops demo recording and returns false on write error.
bool CL_WriteDemoMessage(sizebuf_t *buf)
{
uint32_t msglen;
ssize_t ret;
int ret;

if (buf->overflowed) {
SZ_Clear(buf);
Expand Down Expand Up @@ -529,7 +529,7 @@ static int read_first_message(qhandle_t f)
uint32_t ul;
uint16_t us;
size_t msglen;
ssize_t read;
int read;
qerror_t ret;
int type;

Expand Down Expand Up @@ -590,7 +590,7 @@ static int read_first_message(qhandle_t f)
static int read_next_message(qhandle_t f)
{
uint32_t msglen;
ssize_t read;
int read;

// read msglen
read = FS_Read(&msglen, 4, f);
Expand Down Expand Up @@ -876,7 +876,7 @@ Called after the first valid frame is parsed from the demo.
*/
void CL_FirstDemoFrame(void)
{
ssize_t len, ofs;
int64_t len, ofs;

Com_DPrintf("[%d] first frame\n", cl.frame.number);

Expand Down
17 changes: 10 additions & 7 deletions src/client/download.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ void CL_LoadDownloadIgnores(void)
{
string_entry_t *entry, *next;
char *raw, *data, *p;
int count, line;
ssize_t len;
int len, count, line;

// free previous entries
for (entry = cls.download.ignores; entry; entry = next) {
Expand Down Expand Up @@ -237,7 +236,7 @@ static bool start_udp_download(dlqueue_t *q)
{
size_t len;
qhandle_t f;
ssize_t ret;
int64_t ret;

len = strlen(q->path);
if (len >= MAX_QPATH) {
Expand All @@ -253,22 +252,26 @@ static bool start_udp_download(dlqueue_t *q)
// check to see if we already have a tmp for this file, if so, try to resume
// open the file if not opened yet
ret = FS_FOpenFile(cls.download.temp, &f, FS_MODE_RDWR);
if (ret > INT_MAX) {
FS_FCloseFile(f);
ret = -EFBIG;
}
if (ret >= 0) { // it exists
cls.download.file = f;
cls.download.position = ret;
// give the server an offset to start the download
Com_DPrintf("[UDP] Resuming %s\n", q->path);
#if USE_ZLIB
if (cls.serverProtocol == PROTOCOL_VERSION_R1Q2)
CL_ClientCommand(va("download \"%s\" %"PRIz" udp-zlib", q->path, ret));
CL_ClientCommand(va("download \"%s\" %d udp-zlib", q->path, (int)ret));
else
#endif
CL_ClientCommand(va("download \"%s\" %"PRIz, q->path, ret));
CL_ClientCommand(va("download \"%s\" %d", q->path, (int)ret));
} else if (ret == Q_ERR_NOENT) { // it doesn't exist
Com_DPrintf("[UDP] Downloading %s\n", q->path);
#if USE_ZLIB
if (cls.serverProtocol == PROTOCOL_VERSION_R1Q2)
CL_ClientCommand(va("download \"%s\" %"PRIz" udp-zlib", q->path, (size_t)0));
CL_ClientCommand(va("download \"%s\" %d udp-zlib", q->path, 0));
else
#endif
CL_ClientCommand(va("download \"%s\"", q->path));
Expand Down Expand Up @@ -343,7 +346,7 @@ static void finish_udp_download(const char *msg)

static int write_udp_download(byte *data, int size)
{
ssize_t ret;
int ret;

ret = FS_Write(data, size, cls.download.file);
if (ret != size) {
Expand Down
3 changes: 2 additions & 1 deletion src/client/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ Fetches data from an arbitrary URL in a blocking fashion. Doesn't touch any
global variables and thus doesn't interfere with existing client downloads.
===============
*/
ssize_t HTTP_FetchFile(const char *url, void **data) {
int HTTP_FetchFile(const char *url, void **data)
{
dlhandle_t tmp;
CURL *curl;
CURLcode ret;
Expand Down
2 changes: 1 addition & 1 deletion src/client/sound/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ sfxcache_t *S_LoadSound(sfx_t *s)
{
byte *data;
sfxcache_t *sc;
ssize_t len;
int len;
char *name;

if (s->name[0] == '*')
Expand Down
2 changes: 1 addition & 1 deletion src/client/ui/servers.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ static void ParseAddressBook(void)
static void ParseMasterArgs(netadr_t *broadcast)
{
void *data;
ssize_t len;
int len;
void (*parse)(void *, size_t, size_t);
size_t chunk;
char *s, *p;
Expand Down
2 changes: 1 addition & 1 deletion src/common/bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,7 @@ static bool BSP_LoadPatchedPVS(bsp_t *bsp)
return false;

unsigned char* filebuf = 0;
ssize_t filelen = 0;
int filelen = 0;
filelen = FS_LoadFile(pvs_path, (void**)&filebuf);

if (filebuf == 0)
Expand Down
2 changes: 1 addition & 1 deletion src/common/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1610,7 +1610,7 @@ void Cmd_ExecuteString(cmdbuf_t *buf, const char *text)
qerror_t Cmd_ExecuteFile(const char *path, unsigned flags)
{
char *f;
ssize_t len;
int len;
qerror_t ret;
cmdbuf_t *buf;

Expand Down
2 changes: 1 addition & 1 deletion src/common/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ static void logfile_write(print_type_t type, const char *s)
char buf[MAX_QPATH];
char *p, *maxp;
size_t len;
ssize_t ret;
int ret;
int c;

if (logfile_prefix->string[0]) {
Expand Down
Loading

0 comments on commit ff729e4

Please sign in to comment.