Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit cb61062

Browse files
authored
Merge pull request #5047 from peter-b/coverity
[Coverity] Fix some "uninitialised pointer field" defects
2 parents 4a33281 + 04927ae commit cb61062

File tree

17 files changed

+209
-212
lines changed

17 files changed

+209
-212
lines changed

engine/src/exec-interface-field-chunk.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2482,7 +2482,7 @@ void MCField::SetTextStyleElementOfCharChunk(MCExecContext& ctxt, MCNameRef p_in
24822482

24832483
void MCParagraph::GetEncoding(MCExecContext &ctxt, intenum_t &r_encoding)
24842484
{
2485-
if (MCStringIsNative(m_text))
2485+
if (MCStringIsNative(*m_text))
24862486
r_encoding = 0; // nativestring
24872487
else
24882488
r_encoding = 1; // unicode

engine/src/exec.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ enum MCExecValueType
5252

5353
struct MCExecValue
5454
{
55+
public:
56+
MCExecValue()
57+
{
58+
MCMemoryClear(*this);
59+
type = kMCExecValueTypeNone;
60+
}
5561
union
5662
{
5763
MCValueRef valueref_value;

engine/src/handler.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ Boolean MCHandler::gotpass;
5050
////////////////////////////////////////////////////////////////////////////////
5151

5252
MCHandler::MCHandler(uint1 htype, bool p_is_private)
53+
: hlist(),
54+
npassedparams(),
55+
firstline(),
56+
lastline()
5357
{
5458
statements = NULL;
5559
vars = NULL;

engine/src/ide.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ MCIdeState *MCIdeState::s_states = NULL;
9292
MCIdeState *MCIdeState::s_cache = NULL;
9393

9494
MCIdeState::MCIdeState(void)
95-
: f_next(NULL), f_line_count(0), f_line_properties(0)
95+
: f_next(NULL), f_field(nullptr), f_line_count(0), f_line_properties(0)
9696
{
9797
}
9898

engine/src/lnxdc.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,7 @@ MCGFloat MCResGetSystemScale(void)
7070

7171
MCScreenDC::MCScreenDC()
7272
{
73-
ncolors = 0;
74-
ownselection = False;
75-
pendingevents = NULL;
76-
backdrop = DNULL;
77-
78-
m_backdrop_pixmap = nil;
79-
80-
//Xinerama_available = false ;
81-
//getdisplays_init = false ;
82-
8373
m_application_has_focus = true ; // The application start's up having focus, one assumes.
84-
85-
backdrop_hard = false;
86-
backdrop_active = false;
87-
88-
m_has_native_theme = false;
89-
m_has_native_color_dialogs = false;
90-
m_has_native_file_dialogs = false;
91-
m_has_native_print_dialogs = false;
92-
93-
m_im_context = NULL;
9474
}
9575

9676
MCScreenDC::~MCScreenDC()
@@ -110,8 +90,6 @@ MCScreenDC::~MCScreenDC()
11090
delete allocs;
11191
}
11292

113-
MCNameDelete(vendorname);
114-
11593
while (pendingevents != NULL)
11694
{
11795
MCEventnode *tptr =(MCEventnode *)pendingevents->remove

engine/src/lnxdc.h

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -110,63 +110,63 @@ extern Boolean tripleclick;
110110

111111
class MCScreenDC : public MCUIDC
112112
{
113-
GdkGC* gc; // This is the GC in "Native" (i.e. actual screen) depth
113+
GdkGC* gc = nullptr; // This is the GC in "Native" (i.e. actual screen) depth
114114

115-
bool m_application_has_focus ; // This allows us to track if the application is at the front.
115+
bool m_application_has_focus = false; // This allows us to track if the application is at the front.
116116

117-
Atom statusatom;
118-
Atom selectionatom;
117+
Atom statusatom = GDK_NONE;
118+
Atom selectionatom = GDK_NONE;
119119

120-
uint2 destdepth; //
120+
uint2 destdepth = 0; //
121121

122-
Boolean opened;
122+
Boolean opened = false;
123123

124-
Window Xwin; //
125-
Window NULLWindow ;
124+
Window Xwin = None; //
125+
Window NULLWindow = None;
126126

127-
MCEventnode *pendingevents;
127+
MCEventnode *pendingevents = nullptr;
128128

129-
Boolean ownselection;
129+
Boolean ownselection = False;
130130
MCString selectiontext;
131-
Boolean doubleclick;
131+
Boolean doubleclick = False;
132132

133-
GdkColormap *cmap; // Native colourmap
134-
GdkColormap *cmap32 ; // 32-bit colourmap
133+
GdkColormap *cmap = nullptr; // Native colourmap
134+
GdkColormap *cmap32 = nullptr; // 32-bit colourmap
135135

136-
GdkVisual *vis; // Native visual
137-
GdkVisual *vis32 ; // 32-bit visual
136+
GdkVisual *vis = nullptr; // Native visual
137+
GdkVisual *vis32 = nullptr; // 32-bit visual
138138

139-
bool backdrop_active;
140-
bool backdrop_hard;
141-
Window backdrop;
142-
MCColor backdropcolor;
139+
bool backdrop_active = false;
140+
bool backdrop_hard = false;
141+
Window backdrop = None;
142+
MCColor backdropcolor {0, 0, 0};
143143
// IM-2014-04-15: [[ Bug 11603 ]] Store converted backdrop pattern pixmap
144-
Pixmap m_backdrop_pixmap;
144+
Pixmap m_backdrop_pixmap = nullptr;
145145

146-
Window last_window ; //XDND - Used for the moment to shunt the ID
146+
Window last_window = None; //XDND - Used for the moment to shunt the ID
147147

148-
bool m_has_native_theme;
149-
bool m_has_native_color_dialogs;
150-
bool m_has_native_print_dialogs;
151-
bool m_has_native_file_dialogs;
148+
bool m_has_native_theme = false;
149+
bool m_has_native_color_dialogs = false;
150+
bool m_has_native_print_dialogs = false;
151+
bool m_has_native_file_dialogs = false;
152152

153153
// Set if GTK is available
154-
bool m_has_gtk;
154+
bool m_has_gtk = false;
155155

156156
// Input context for IME integration
157-
GtkIMContext *m_im_context;
157+
GtkIMContext *m_im_context = nullptr;
158158

159159
public:
160160

161-
char * syslocale ;
161+
char * syslocale = nullptr;
162162

163-
GdkDisplay *dpy;
164-
Boolean has_composite_wm ;
165-
Drawable dest; //
163+
GdkDisplay *dpy = nullptr;
164+
Boolean has_composite_wm = false;
165+
Drawable dest = None; //
166166

167-
MCNameRef displayname;
168-
MCNameRef vendorname;
169-
uint4 savedpixel; // Move into per-context
167+
MCNewAutoNameRef displayname;
168+
MCNewAutoNameRef vendorname;
169+
uint4 savedpixel = 0; // Move into per-context
170170

171171
MCScreenDC();
172172
virtual ~MCScreenDC();

engine/src/lnxdcs.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,26 @@ Boolean MCScreenDC::open()
254254
GdkScreen *t_screen;
255255
t_screen = gdk_display_get_default_screen(dpy);
256256

257-
MCAutoStringRef t_displayname;
258-
/* UNCHECKED */ MCStringCreateWithSysString(gdk_display_get_name(dpy), &t_displayname);
259-
/* UNCHECKED */ MCNameCreate(*t_displayname, displayname);
257+
{
258+
MCAutoStringRef t_displayname;
259+
MCNewAutoNameRef t_displayname_asname;
260+
if (MCStringCreateWithSysString(gdk_display_get_name(dpy),
261+
&t_displayname) &&
262+
MCNameCreate(*t_displayname, &t_displayname_asname))
263+
{
264+
displayname.Reset(t_displayname_asname.Take());
265+
}
266+
}
260267
{
261268
MCAutoStringRef t_vendor_string, t_vendor;
262-
/* UNCHECKED */ MCStringCreateWithSysString(x11::XServerVendor(XDisplay), &t_vendor);
263-
/* UNCHECKED */ MCStringFormat(&t_vendor_string, "%@ %d", *t_vendor, x11::XVendorRelease(XDisplay));
264-
MCNameCreate(*t_vendor_string, vendorname);
269+
MCNewAutoNameRef t_vendorname;
270+
if (MCStringCreateWithSysString(x11::XServerVendor(XDisplay), &t_vendor) &&
271+
MCStringFormat(&t_vendor_string, "%@ %d", *t_vendor,
272+
x11::XVendorRelease(XDisplay)) &&
273+
MCNameCreate(*t_vendor_string, &t_vendorname))
274+
{
275+
vendorname.Reset(t_vendorname.Take());
276+
}
265277
}
266278

267279
#ifdef SYNCMODE
@@ -575,7 +587,7 @@ Boolean MCScreenDC::close(Boolean force)
575587

576588
MCNameRef MCScreenDC::getdisplayname()
577589
{
578-
return displayname;
590+
return *displayname;
579591
}
580592

581593

@@ -1024,7 +1036,7 @@ void MCScreenDC::setbeep(uint4 which, int4 beep)
10241036

10251037
MCNameRef MCScreenDC::getvendorname(void)
10261038
{
1027-
return vendorname;
1039+
return *vendorname;
10281040
}
10291041

10301042
uint2 MCScreenDC::getpad()

engine/src/mcerror.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,36 +93,38 @@ void MCError::doadd(uint2 id, uint2 line, uint2 pos, MCStringRef p_token)
9393

9494
MCValueRelease(t_line);
9595
}
96-
if (!MCStringIsEmpty(buffer))
97-
MCStringAppendChar(buffer, '\n');
96+
if (!MCStringIsEmpty(*buffer))
97+
/* UNCHECKED */ MCStringAppendChar(*buffer, '\n');
9898

99-
MCStringAppend(buffer, *newerror);
99+
/* UNCHECKED */ MCStringAppend(*buffer, *newerror);
100100
depth += 1;
101101
}
102102

103103
void MCError::append(MCError& p_other)
104104
{
105-
MCStringAppendFormat(buffer, MCStringIsEmpty(buffer) ? "%@" : "\n%@", p_other . buffer);
105+
/* UNCHECKED */ MCStringAppendFormat(*buffer,
106+
MCStringIsEmpty(*buffer) ? "%@" : "\n%@",
107+
*p_other.buffer);
106108
}
107109

108110
void MCError::copystringref(MCStringRef s, Boolean t)
109111
{
110-
MCValueRelease(buffer);
111-
MCStringMutableCopy(s, buffer);
112+
buffer.Reset();
113+
/* UNCHECKED */ MCStringMutableCopy(s, &buffer);
112114
thrown = t;
113115
}
114116

115117
bool MCError::copyasstringref(MCStringRef &r_string)
116118
{
117-
return MCStringCopy(buffer, r_string);
119+
return MCStringCopy(*buffer, r_string);
118120
}
119121

120122
void MCError::clear()
121123
{
122-
MCValueRelease(buffer);
123124
errorline = errorpos = 0;
124125
depth = 0;
125-
MCStringCreateMutable(0, buffer);
126+
buffer.Reset();
127+
/* UNCHECKED */ MCStringCreateMutable(0, &buffer);
126128
thrown = False;
127129
if (this == MCeerror)
128130
MCerrorptr = nil;

engine/src/mcerror.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,19 @@ class MCScriptPoint;
2424

2525
class MCError
2626
{
27-
MCStringRef buffer;
27+
MCAutoStringRef buffer;
2828
uint2 errorline;
2929
uint2 errorpos;
3030
uint2 depth;
3131
Boolean thrown;
3232
public:
3333
MCError()
3434
{
35-
MCStringCreateMutable(0, buffer);
35+
/* UNCHECKED */ MCStringCreateMutable(0, &buffer);
3636
errorline = errorpos = 0;
3737
depth = 0;
3838
thrown = False;
3939
}
40-
~MCError()
41-
{
42-
MCValueRelease(buffer);
43-
}
4440
void add(uint2 id, MCScriptPoint &);
4541
void add(uint2 id, uint2 line, uint2 pos);
4642
void add(uint2 id, uint2 line, uint2 pos, uint32_t);
@@ -53,7 +49,7 @@ class MCError
5349
void clear();
5450
Boolean isempty()
5551
{
56-
return MCStringIsEmpty(buffer);
52+
return MCStringIsEmpty(*buffer);
5753
}
5854
void geterrorloc(uint2 &line, uint2 &pos);
5955

0 commit comments

Comments
 (0)