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:
Jan Engelhardt
2025-06-06 10:53:41 +02:00
parent c68f6b029a
commit 5ca72cba5b
7 changed files with 25 additions and 27 deletions

View File

@@ -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 = 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_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_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++) { for (j = 0; j < Rooms[i].num_bbf_regions; j++) {
Rooms[i].num_bbf[j] = cf_ReadShort(fp); Rooms[i].num_bbf[j] = cf_ReadShort(fp);

View File

@@ -630,7 +630,7 @@ int cfgetc(CFILE *cfp) {
if (cfp->position >= cfp->size) if (cfp->position >= cfp->size)
return EOF; return EOF;
fread(ch, sizeof(char), 1, cfp->file); fread(ch, 1, 1, cfp->file);
c = ch[0]; c = ch[0];
// c = getc( cfp->file ); // c = getc( cfp->file );
if (cfeof(cfp)) if (cfeof(cfp))
@@ -644,7 +644,7 @@ int cfgetc(CFILE *cfp) {
if (c == 10) // return LF as newline if (c == 10) // return LF as newline
c = '\n'; c = '\n';
else if (c == 13) { // check for CR/LF pair 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); int cc = ch[0]; // getc(cfp->file);
// if (cc != EOF) { // if (cc != EOF) {
if (!cfeof(cfp)) { if (!cfeof(cfp)) {

View File

@@ -123,7 +123,7 @@ bool ReadHogHeader(FILE *fp, tHogHeader *header) {
} }
bool ReadHogEntry(FILE *fp, tHogFileEntry *entry) { 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; return false;
if (fread(&entry->flags, sizeof(entry->flags), 1, fp) != 1) if (fread(&entry->flags, sizeof(entry->flags), 1, fp) != 1)
return false; return false;

View File

@@ -239,7 +239,7 @@ int CHogEditDoc::LoadRib(const char *pathname) {
} }
// Read in the hog filename // 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); fclose(rib_fp);
return false; return false;
} }
@@ -379,7 +379,7 @@ int CHogEditDoc::SaveRib(const char *pathname) {
} }
// write out the hog filename // 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); fclose(rib_fp);
return false; return false;
} }
@@ -499,8 +499,8 @@ int CHogEditDoc::UpdatedFileCheck(hog_library_entry *entry) {
// Loads a Hog library entry structure // Loads a Hog library entry structure
bool CHogEditDoc::ReadHogLibEntry(FILE *fp, hog_library_entry *entry) { bool CHogEditDoc::ReadHogLibEntry(FILE *fp, hog_library_entry *entry) {
int res = 0; int res = 0;
res = fread(entry->path, sizeof(char), _MAX_PATH, fp); res = fread(entry->path, 1, _MAX_PATH, fp);
res = fread(entry->name, sizeof(char), PSFILENAME_LEN + 1, fp); res = fread(entry->name, 1, PSFILENAME_LEN + 1, fp);
res = fread(&entry->flags, sizeof(entry->flags), 1, fp); res = fread(&entry->flags, sizeof(entry->flags), 1, fp);
res = fread(&entry->length, sizeof(entry->length), 1, fp); res = fread(&entry->length, sizeof(entry->length), 1, fp);
res = fread(&entry->timestamp, sizeof(entry->timestamp), 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 // Saves a Hog library entry structure
bool CHogEditDoc::WriteHogLibEntry(FILE *fp, hog_library_entry *entry) { bool CHogEditDoc::WriteHogLibEntry(FILE *fp, hog_library_entry *entry) {
int res = 0; int res = 0;
res = fwrite(entry->path, sizeof(char), _MAX_PATH, fp); res = fwrite(entry->path, 1, _MAX_PATH, fp);
res = fwrite(entry->name, sizeof(char), PSFILENAME_LEN + 1, fp); res = fwrite(entry->name, 1, PSFILENAME_LEN + 1, fp);
res = fwrite(&entry->flags, sizeof(entry->flags), 1, fp); res = fwrite(&entry->flags, sizeof(entry->flags), 1, fp);
res = fwrite(&entry->length, sizeof(entry->length), 1, fp); res = fwrite(&entry->length, sizeof(entry->length), 1, fp);
res = fwrite(&entry->timestamp, sizeof(entry->timestamp), 1, fp); res = fwrite(&entry->timestamp, sizeof(entry->timestamp), 1, fp);

View File

@@ -918,12 +918,12 @@ void GetGameStartPacket(uint8_t *data) {
// who has the powerball // who has the powerball
int8_t temp; int8_t temp;
memcpy(&temp, &data[size], sizeof(char)); memcpy(&temp, &data[size], 1);
size += sizeof(char); size += 1;
WhoHasPowerBall = temp; WhoHasPowerBall = temp;
memcpy(&temp, &data[size], sizeof(char)); memcpy(&temp, &data[size], 1);
size += sizeof(char); size += 1;
NumOfTeams = temp; NumOfTeams = temp;
// Now based on what we have from the server set up our info // 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) { void SendGameStartPacket(int pnum) {
int maxsize = sizeof(int) * DLLMAX_TEAMS + 2 * sizeof(char); int maxsize = sizeof(int) * DLLMAX_TEAMS + 2;
int size = 0; int size = 0;
uint8_t *data = PBall.StartPacket(maxsize, SPID_NEWPLAYER); uint8_t *data = PBall.StartPacket(maxsize, SPID_NEWPLAYER);
@@ -960,13 +960,13 @@ void SendGameStartPacket(int pnum) {
int8_t temp; int8_t temp;
// who has the powerball if anyone // who has the powerball if anyone
temp = WhoHasPowerBall; temp = WhoHasPowerBall;
memcpy(&data[size], &temp, sizeof(char)); memcpy(&data[size], &temp, 1);
size += sizeof(char); size += 1;
// number of teams // number of teams
temp = NumOfTeams; temp = NumOfTeams;
memcpy(&data[size], &temp, sizeof(char)); memcpy(&data[size], &temp, 1);
size += sizeof(char); size += 1;
// we're done // we're done
DLLmprintf(0, "Sending Game State to %s\n", PBall.Players[pnum].callsign); DLLmprintf(0, "Sending Game State to %s\n", PBall.Players[pnum].callsign);

View File

@@ -143,14 +143,14 @@ bool con_raw_Create() {
Con_raw_rows = 24; // one less, since the bottom window takes up one row Con_raw_rows = 24; // one less, since the bottom window takes up one row
// allocate any memory needed for buffers // allocate any memory needed for buffers
Con_raw_inp_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 = (char *)malloc(sizeof(char) * (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) { if (!Con_raw_inp_buf || !Con_raw_read_buf) {
// error allocating memory // error allocating memory
return false; return false;
} }
memset(Con_raw_inp_buf, 0, sizeof(char) * (Con_raw_cols + 4)); memset(Con_raw_inp_buf, 0, Con_raw_cols + 4);
memset(Con_raw_read_buf, 0, sizeof(char) * (Con_raw_cols + 4)); memset(Con_raw_read_buf, 0, Con_raw_cols + 4);
Con_raw_last_command[0] = '\0'; Con_raw_last_command[0] = '\0';
Con_raw_inp_pos = 0; Con_raw_inp_pos = 0;

View File

@@ -160,9 +160,8 @@ void ReceivePickupVirus(uint8_t *data) {
// MTS: only used in this file. // MTS: only used in this file.
void SendRoomInfo(int pnum) { void SendRoomInfo(int pnum) {
char *room_info = NULL;
int flags, r, i; int flags, r, i;
room_info = (char *)malloc(sizeof(char) * RoomCount); auto room_info = static_cast<char *>(malloc(RoomCount));
if (!room_info) if (!room_info)
return; return;
@@ -210,8 +209,7 @@ void SendRoomInfo(int pnum) {
void ReceiveRoomInfo(uint8_t *data) { void ReceiveRoomInfo(uint8_t *data) {
int i, count = 0; int i, count = 0;
int flag; int flag;
char *room_info; auto room_info = static_cast<char *>(malloc(RoomCount));
room_info = (char *)malloc(sizeof(char) * RoomCount);
if (!room_info) { if (!room_info) {
FatalError("Out of Memory"); FatalError("Out of Memory");
return; return;