Skip to content

Commit 0171d7b

Browse files
authored
Merge pull request #720 from jengelh/Wchar
Resolve 160 instances of -Wchar-subscript
2 parents c68f6b0 + dee5467 commit 0171d7b

26 files changed

+103
-87
lines changed

Descent3/AIGoal.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@
463463
* $NoKeywords: $
464464
*/
465465

466+
#include <cstdint>
466467
#include <cstdlib>
467468

468469
#include "AIGoal.h"
@@ -1096,7 +1097,7 @@ int GoalAddGoal(object *obj, uint32_t goal_type, void *arg_struct, int level, fl
10961097
if ((ai_info->animation_type == AS_ALERT) || (ai_info->animation_type == AS_MELEE1 + 1) ||
10971098
(ai_info->animation_type == AS_MELEE2 + 1)) {
10981099
uint8_t m_num = attack_info->melee_number;
1099-
char new_anim;
1100+
int8_t new_anim;
11001101

11011102
if (m_num)
11021103
new_anim = AS_MELEE1;
@@ -1116,7 +1117,7 @@ int GoalAddGoal(object *obj, uint32_t goal_type, void *arg_struct, int level, fl
11161117
break;
11171118

11181119
case AIG_SET_ANIM: {
1119-
char new_anim = *((int *)arg_struct);
1120+
int8_t new_anim = *static_cast<int *>(arg_struct);
11201121
polyobj_info *p_info = &obj->rtype.pobj_info;
11211122

11221123
// mprintf(0, "Anim Goal %d\n", new_anim);

Descent3/AImain.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,7 @@
15071507
* $NoKeywords: $
15081508
*/
15091509

1510+
#include <cstdint>
15101511
#include <cstdlib>
15111512

15121513
#include "AIMain.h"
@@ -3346,7 +3347,7 @@ void ai_do_animation(object *obj, float anim_time) {
33463347
}
33473348
} else {
33483349
if (obj->ai_info->animation_type == AS_RANGED_ATTACK) {
3349-
char wb = obj->ai_info->last_special_wb_firing;
3350+
int8_t wb = obj->ai_info->last_special_wb_firing;
33503351

33513352
if (Object_info[obj->id].static_wb[wb].flags & WBF_SPRAY) {
33523353
obj->weapon_fire_flags |= WFF_SPRAY;
@@ -6059,7 +6060,7 @@ void AIDoFrame(object *obj) {
60596060
// Handle On/off and spray weapons
60606061
{
60616062
if ((obj->weapon_fire_flags & WFF_SPRAY) && !(obj->flags & (OF_DESTROYED | OF_DYING))) {
6062-
char wb_index = ai_info->last_special_wb_firing;
6063+
int8_t wb_index = ai_info->last_special_wb_firing;
60636064
DoSprayEffect(obj, &Object_info[obj->id].static_wb[wb_index], wb_index);
60646065
if (!((Game_mode & GM_MULTI) && (Netgame.local_role == LR_CLIENT))) {
60656066
if (WBIsBatteryReady(obj, &Object_info[obj->id].static_wb[wb_index], wb_index) &&

Descent3/LoadLevel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3165,7 +3165,7 @@ void ReadRoomAABBChunk(CFILE *fp, int version) {
31653165
Rooms[i].bbf_list = mem_rmalloc<int16_t *>(Rooms[i].num_bbf_regions);
31663166
Rooms[i].bbf_list_min_xyz = mem_rmalloc<vector>(Rooms[i].num_bbf_regions);
31673167
Rooms[i].bbf_list_max_xyz = mem_rmalloc<vector>(Rooms[i].num_bbf_regions);
3168-
Rooms[i].bbf_list_sector = mem_rmalloc<uint8_t>(sizeof(char) * Rooms[i].num_bbf_regions);
3168+
Rooms[i].bbf_list_sector = mem_rmalloc<uint8_t>(Rooms[i].num_bbf_regions);
31693169

31703170
for (j = 0; j < Rooms[i].num_bbf_regions; j++) {
31713171
Rooms[i].num_bbf[j] = cf_ReadShort(fp);

Descent3/PilotPicsAPI.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
*/
6060

6161
#include <algorithm>
62+
#include <cstdint>
6263
#include <cstdlib>
6364
#include <cstdio>
6465

@@ -561,7 +562,7 @@ bool PPic_BuildDatabases(void) {
561562
Pilot_id_to_offset[count].offset = file_pos;
562563
Pilot_id_to_offset[count].id = pilot_id;
563564

564-
char let_pos;
565+
int8_t let_pos;
565566
if (isalpha(name_buffer[0])) {
566567
let_pos = toupper(name_buffer[0]) - 'A';
567568
} else {

Descent3/TelComGoals.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static int TG_MouseOffset_x = -1, TG_MouseOffset_y = -1;
140140
bool TG_compare_slots(int left, int right) {
141141
int left_index, right_index;
142142
int left_priority, right_priority;
143-
char left_list, right_list;
143+
int8_t left_list, right_list;
144144

145145
left_index = TG_Lines[left].goal_index;
146146
right_index = TG_Lines[right].goal_index;

Descent3/aiambient.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19+
#include <cstdint>
1920
#include <stdlib.h>
2021
#include "aiambient.h"
2122
#include "string.h"
@@ -30,7 +31,7 @@ ambient_life a_life;
3031
void ambient_life::DoFrame(void) {}
3132

3233
void ambient_life::InitForLevel(void) {
33-
char i;
34+
int8_t i;
3435

3536
for (i = 0; i < MAX_AL_TYPES; i++) {
3637
ComputeNextSize(i);
@@ -41,7 +42,7 @@ void ambient_life::InitForLevel(void) {
4142
DoFrame();
4243
}
4344

44-
void ambient_life::GetALValue(char i, char field, void *ptr) {
45+
void ambient_life::GetALValue(int8_t i, char field, void *ptr) {
4546
switch (field) {
4647
case ALI_TYPE:
4748
*((int *)ptr) = m_type[i];
@@ -61,7 +62,7 @@ void ambient_life::GetALValue(char i, char field, void *ptr) {
6162
}
6263
}
6364

64-
void ambient_life::ComputeNextSize(char i) {
65+
void ambient_life::ComputeNextSize(int8_t i) {
6566
char diff = m_max[i] - m_min[i];
6667
if (diff > 0) {
6768
char offset = ps_rand() % diff;
@@ -71,7 +72,7 @@ void ambient_life::ComputeNextSize(char i) {
7172
}
7273
}
7374

74-
void ambient_life::SetALValue(char i, char field, void *ptr) {
75+
void ambient_life::SetALValue(int8_t i, char field, void *ptr) {
7576
switch (field) {
7677
case ALI_TYPE:
7778
m_type[i] = *((int *)ptr);

Descent3/aiambient.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#ifndef _AIAMBIENT_H_
2020
#define _AIAMBIENT_H_
2121

22+
#include <cstdint>
2223
#include "cfile.h"
2324

2425
#define MAX_AL_TYPES 6
@@ -51,13 +52,13 @@ class ambient_life {
5152
uint8_t m_next_size[MAX_AL_TYPES];
5253
float m_next_do_time[MAX_AL_TYPES];
5354

54-
void ComputeNextSize(char index);
55+
void ComputeNextSize(int8_t index);
5556

5657
public:
5758
ambient_life() { ALReset(); }
5859

59-
void GetALValue(char index, char field, void *ptr);
60-
void SetALValue(char index, char field, void *ptr);
60+
void GetALValue(int8_t index, char field, void *ptr);
61+
void SetALValue(int8_t index, char field, void *ptr);
6162
void SaveData(CFILE *fptr);
6263
void LoadData(CFILE *fptr);
6364

Descent3/aistruct.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@
392392
#ifndef AISTRUCT_H_
393393
#define AISTRUCT_H_
394394

395+
#include <cstdint>
395396
#include "pstypes.h"
396397
#include "vecmat.h"
397398
#include "aistruct_external.h"
@@ -759,10 +760,9 @@ struct ai_frame {
759760
float last_sound_time[MAX_AI_SOUNDS];
760761
int16_t last_played_sound_index;
761762

762-
char movement_type;
763-
char movement_subtype;
763+
int8_t movement_type, movement_subtype;
764764

765-
char animation_type;
765+
int8_t animation_type;
766766
char next_animation_type;
767767

768768
char next_movement; // For queueing actions :)

Descent3/attach.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19+
#include <cstdint>
1920
#include "attach.h"
2021
#include "terrain.h"
2122
#include "log.h"
@@ -142,7 +143,7 @@ PI); rot_angle = acos(dot);
142143

143144
// Finds the position of a attach point on an object
144145
// The uvec is optional as most attaching objects don't need at complete orientation set (only an fvec)
145-
static bool AttachPointPos(object *obj, char ap, bool f_compute_pos, vector *attach_pos, bool f_compute_fvec,
146+
static bool AttachPointPos(object *obj, int8_t ap, bool f_compute_pos, vector *attach_pos, bool f_compute_fvec,
146147
vector *attach_fvec, bool *f_computed_uvec = NULL, vector *attach_uvec = NULL) {
147148
poly_model *pm;
148149
vector pnt;
@@ -459,7 +460,7 @@ static void ProprogateUltimateAttachParent(object *parent, int ultimate_handle)
459460

460461
// Attaches 2 objects via attach points on each. The f_used_aligned allows for an aligned connection.
461462
// NOTE: The child always moves to the parent
462-
bool AttachObject(object *parent, char parent_ap, object *child, char child_ap, bool f_use_aligned) {
463+
bool AttachObject(object *parent, int8_t parent_ap, object *child, char child_ap, bool f_use_aligned) {
463464
ASSERT(parent);
464465
ASSERT(child);
465466

@@ -510,7 +511,7 @@ bool AttachObject(object *parent, char parent_ap, object *child, char child_ap,
510511

511512
// Attaches a child object to a parent object by a percent of the radius of the child.
512513
// NOTE: The child always moves to the parent and not the reverse
513-
bool AttachObject(object *parent, char parent_ap, object *child, float percent_rad) {
514+
bool AttachObject(object *parent, int8_t parent_ap, object *child, float percent_rad) {
514515
ASSERT(parent);
515516
ASSERT(child);
516517

@@ -661,7 +662,7 @@ bool UnattachFromParent(object *child) {
661662
}
662663

663664
// Unattaches a child from an attach point
664-
bool UnattachChild(object *parent, char parent_ap) {
665+
bool UnattachChild(object *parent, int8_t parent_ap) {
665666
object *child;
666667

667668
if ((child = ObjGet(parent->attach_children[parent_ap])) != NULL) {

Descent3/attach.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@
1919
#ifndef _ATTACH_H_
2020
#define _ATTACH_H_
2121

22+
#include <cstdint>
2223
#include "object.h"
2324

2425
bool AttachDoPosOrient(object *parent, char parent_ap, object *child, char child_ap, bool f_parent,
2526
bool f_move_obj = true, vector *pos = NULL, matrix *orient = NULL, bool f_dropping_off = false);
2627
bool AttachDoPosOrientRad(object *parent, char p_ap, object *child, float rad_percent, vector *pos);
2728
void AttachUpdateSubObjects(object *obj);
2829

29-
bool AttachObject(object *parent, char parent_ap, object *child, char child_ap, bool f_use_aligned = false);
30-
bool AttachObject(object *parent, char parent_ap, object *child, float percent_rad);
30+
bool AttachObject(object *parent, int8_t parent_ap, object *child, char child_ap, bool f_use_aligned = false);
31+
bool AttachObject(object *parent, int8_t parent_ap, object *child, float percent_rad);
3132
bool UnattachFromParent(object *child);
32-
bool UnattachChild(object *parent, char parent_ap);
33+
bool UnattachChild(object *parent, int8_t parent_ap);
3334
bool UnattachChildren(object *parent);
3435

3536
#endif

0 commit comments

Comments
 (0)