mirror of
https://github.com/kevinbentley/Descent3.git
synced 2025-12-19 09:27:48 -05:00
Replace sizeof(char) by 1
sizeof(char) is 1 by definition. This simplifies some multiplication statements. https://en.cppreference.com/w/cpp/language/sizeof.html
This commit is contained in:
@@ -3165,7 +3165,7 @@ void ReadRoomAABBChunk(CFILE *fp, int version) {
|
||||
Rooms[i].bbf_list = mem_rmalloc<int16_t *>(Rooms[i].num_bbf_regions);
|
||||
Rooms[i].bbf_list_min_xyz = mem_rmalloc<vector>(Rooms[i].num_bbf_regions);
|
||||
Rooms[i].bbf_list_max_xyz = mem_rmalloc<vector>(Rooms[i].num_bbf_regions);
|
||||
Rooms[i].bbf_list_sector = mem_rmalloc<uint8_t>(sizeof(char) * Rooms[i].num_bbf_regions);
|
||||
Rooms[i].bbf_list_sector = mem_rmalloc<uint8_t>(Rooms[i].num_bbf_regions);
|
||||
|
||||
for (j = 0; j < Rooms[i].num_bbf_regions; j++) {
|
||||
Rooms[i].num_bbf[j] = cf_ReadShort(fp);
|
||||
|
||||
@@ -630,7 +630,7 @@ int cfgetc(CFILE *cfp) {
|
||||
if (cfp->position >= cfp->size)
|
||||
return EOF;
|
||||
|
||||
fread(ch, sizeof(char), 1, cfp->file);
|
||||
fread(ch, 1, 1, cfp->file);
|
||||
c = ch[0];
|
||||
// c = getc( cfp->file );
|
||||
if (cfeof(cfp))
|
||||
@@ -644,7 +644,7 @@ int cfgetc(CFILE *cfp) {
|
||||
if (c == 10) // return LF as newline
|
||||
c = '\n';
|
||||
else if (c == 13) { // check for CR/LF pair
|
||||
fread(ch, sizeof(char), 1, cfp->file);
|
||||
fread(ch, 1, 1, cfp->file);
|
||||
int cc = ch[0]; // getc(cfp->file);
|
||||
// if (cc != EOF) {
|
||||
if (!cfeof(cfp)) {
|
||||
|
||||
@@ -123,7 +123,7 @@ bool ReadHogHeader(FILE *fp, tHogHeader *header) {
|
||||
}
|
||||
|
||||
bool ReadHogEntry(FILE *fp, tHogFileEntry *entry) {
|
||||
if (fread(entry->name, sizeof(char), HOG_FILENAME_LEN, fp) != HOG_FILENAME_LEN)
|
||||
if (fread(entry->name, 1, HOG_FILENAME_LEN, fp) != HOG_FILENAME_LEN)
|
||||
return false;
|
||||
if (fread(&entry->flags, sizeof(entry->flags), 1, fp) != 1)
|
||||
return false;
|
||||
|
||||
@@ -239,7 +239,7 @@ int CHogEditDoc::LoadRib(const char *pathname) {
|
||||
}
|
||||
|
||||
// Read in the hog filename
|
||||
if (!fread(Library.filename, sizeof(char), _MAX_PATH, rib_fp)) {
|
||||
if (!fread(Library.filename, 1, _MAX_PATH, rib_fp)) {
|
||||
fclose(rib_fp);
|
||||
return false;
|
||||
}
|
||||
@@ -379,7 +379,7 @@ int CHogEditDoc::SaveRib(const char *pathname) {
|
||||
}
|
||||
|
||||
// write out the hog filename
|
||||
if (!fwrite(Library.filename, sizeof(char), _MAX_PATH, rib_fp)) {
|
||||
if (!fwrite(Library.filename, 1, _MAX_PATH, rib_fp)) {
|
||||
fclose(rib_fp);
|
||||
return false;
|
||||
}
|
||||
@@ -499,8 +499,8 @@ int CHogEditDoc::UpdatedFileCheck(hog_library_entry *entry) {
|
||||
// Loads a Hog library entry structure
|
||||
bool CHogEditDoc::ReadHogLibEntry(FILE *fp, hog_library_entry *entry) {
|
||||
int res = 0;
|
||||
res = fread(entry->path, sizeof(char), _MAX_PATH, fp);
|
||||
res = fread(entry->name, sizeof(char), PSFILENAME_LEN + 1, fp);
|
||||
res = fread(entry->path, 1, _MAX_PATH, fp);
|
||||
res = fread(entry->name, 1, PSFILENAME_LEN + 1, fp);
|
||||
res = fread(&entry->flags, sizeof(entry->flags), 1, fp);
|
||||
res = fread(&entry->length, sizeof(entry->length), 1, fp);
|
||||
res = fread(&entry->timestamp, sizeof(entry->timestamp), 1, fp);
|
||||
@@ -516,8 +516,8 @@ bool CHogEditDoc::ReadHogLibEntry(FILE *fp, hog_library_entry *entry) {
|
||||
// Saves a Hog library entry structure
|
||||
bool CHogEditDoc::WriteHogLibEntry(FILE *fp, hog_library_entry *entry) {
|
||||
int res = 0;
|
||||
res = fwrite(entry->path, sizeof(char), _MAX_PATH, fp);
|
||||
res = fwrite(entry->name, sizeof(char), PSFILENAME_LEN + 1, fp);
|
||||
res = fwrite(entry->path, 1, _MAX_PATH, fp);
|
||||
res = fwrite(entry->name, 1, PSFILENAME_LEN + 1, fp);
|
||||
res = fwrite(&entry->flags, sizeof(entry->flags), 1, fp);
|
||||
res = fwrite(&entry->length, sizeof(entry->length), 1, fp);
|
||||
res = fwrite(&entry->timestamp, sizeof(entry->timestamp), 1, fp);
|
||||
|
||||
@@ -918,12 +918,12 @@ void GetGameStartPacket(uint8_t *data) {
|
||||
|
||||
// who has the powerball
|
||||
int8_t temp;
|
||||
memcpy(&temp, &data[size], sizeof(char));
|
||||
size += sizeof(char);
|
||||
memcpy(&temp, &data[size], 1);
|
||||
size += 1;
|
||||
WhoHasPowerBall = temp;
|
||||
|
||||
memcpy(&temp, &data[size], sizeof(char));
|
||||
size += sizeof(char);
|
||||
memcpy(&temp, &data[size], 1);
|
||||
size += 1;
|
||||
NumOfTeams = temp;
|
||||
|
||||
// Now based on what we have from the server set up our info
|
||||
@@ -947,7 +947,7 @@ void GetGameStartPacket(uint8_t *data) {
|
||||
}
|
||||
|
||||
void SendGameStartPacket(int pnum) {
|
||||
int maxsize = sizeof(int) * DLLMAX_TEAMS + 2 * sizeof(char);
|
||||
int maxsize = sizeof(int) * DLLMAX_TEAMS + 2;
|
||||
int size = 0;
|
||||
|
||||
uint8_t *data = PBall.StartPacket(maxsize, SPID_NEWPLAYER);
|
||||
@@ -960,13 +960,13 @@ void SendGameStartPacket(int pnum) {
|
||||
int8_t temp;
|
||||
// who has the powerball if anyone
|
||||
temp = WhoHasPowerBall;
|
||||
memcpy(&data[size], &temp, sizeof(char));
|
||||
size += sizeof(char);
|
||||
memcpy(&data[size], &temp, 1);
|
||||
size += 1;
|
||||
|
||||
// number of teams
|
||||
temp = NumOfTeams;
|
||||
memcpy(&data[size], &temp, sizeof(char));
|
||||
size += sizeof(char);
|
||||
memcpy(&data[size], &temp, 1);
|
||||
size += 1;
|
||||
|
||||
// we're done
|
||||
DLLmprintf(0, "Sending Game State to %s\n", PBall.Players[pnum].callsign);
|
||||
|
||||
@@ -143,14 +143,14 @@ bool con_raw_Create() {
|
||||
Con_raw_rows = 24; // one less, since the bottom window takes up one row
|
||||
|
||||
// allocate any memory needed for buffers
|
||||
Con_raw_inp_buf = (char *)malloc(sizeof(char) * (Con_raw_cols + 4));
|
||||
Con_raw_read_buf = (char *)malloc(sizeof(char) * (Con_raw_cols + 4));
|
||||
Con_raw_inp_buf = static_cast<char *>(malloc(Con_raw_cols + 4));
|
||||
Con_raw_read_buf = static_cast<char *>(malloc(Con_raw_cols + 4));
|
||||
if (!Con_raw_inp_buf || !Con_raw_read_buf) {
|
||||
// error allocating memory
|
||||
return false;
|
||||
}
|
||||
memset(Con_raw_inp_buf, 0, sizeof(char) * (Con_raw_cols + 4));
|
||||
memset(Con_raw_read_buf, 0, sizeof(char) * (Con_raw_cols + 4));
|
||||
memset(Con_raw_inp_buf, 0, Con_raw_cols + 4);
|
||||
memset(Con_raw_read_buf, 0, Con_raw_cols + 4);
|
||||
Con_raw_last_command[0] = '\0';
|
||||
|
||||
Con_raw_inp_pos = 0;
|
||||
|
||||
@@ -160,9 +160,8 @@ void ReceivePickupVirus(uint8_t *data) {
|
||||
|
||||
// MTS: only used in this file.
|
||||
void SendRoomInfo(int pnum) {
|
||||
char *room_info = NULL;
|
||||
int flags, r, i;
|
||||
room_info = (char *)malloc(sizeof(char) * RoomCount);
|
||||
auto room_info = static_cast<char *>(malloc(RoomCount));
|
||||
if (!room_info)
|
||||
return;
|
||||
|
||||
@@ -210,8 +209,7 @@ void SendRoomInfo(int pnum) {
|
||||
void ReceiveRoomInfo(uint8_t *data) {
|
||||
int i, count = 0;
|
||||
int flag;
|
||||
char *room_info;
|
||||
room_info = (char *)malloc(sizeof(char) * RoomCount);
|
||||
auto room_info = static_cast<char *>(malloc(RoomCount));
|
||||
if (!room_info) {
|
||||
FatalError("Out of Memory");
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user