(svn r26057) -Fix: a number of possibly uninitialised variables

This commit is contained in:
rubidium 2013-11-23 13:12:19 +00:00
parent 2e54c8fdfa
commit b3e93d6520
13 changed files with 28 additions and 13 deletions

View File

@ -35,6 +35,9 @@ DEFINE_POOL_METHOD(inline)::Pool(const char *name) :
first_free(0), first_free(0),
first_unused(0), first_unused(0),
items(0), items(0),
#ifdef OTTD_ASSERT
checked(0),
#endif /* OTTD_ASSERT */
cleaning(false), cleaning(false),
data(NULL), data(NULL),
alloc_cache(NULL) alloc_cache(NULL)

View File

@ -41,7 +41,8 @@ struct LoadCheckData {
struct LoggedAction *gamelog_action; ///< Gamelog actions struct LoggedAction *gamelog_action; ///< Gamelog actions
uint gamelog_actions; ///< Number of gamelog actions uint gamelog_actions; ///< Number of gamelog actions
LoadCheckData() : error_data(NULL), grfconfig(NULL), gamelog_action(NULL) LoadCheckData() : error_data(NULL), grfconfig(NULL),
grf_compatibility(GLC_NOT_FOUND), gamelog_action(NULL), gamelog_actions(0)
{ {
this->Clear(); this->Clear();
} }

View File

@ -46,9 +46,11 @@ static void ReadHeightmapPNGImageData(byte *map, png_structp png_ptr, png_infop
uint x, y; uint x, y;
byte gray_palette[256]; byte gray_palette[256];
png_bytep *row_pointers = NULL; png_bytep *row_pointers = NULL;
bool has_palette = png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE;
uint channels = png_get_channels(png_ptr, info_ptr);
/* Get palette and convert it to grayscale */ /* Get palette and convert it to grayscale */
if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) { if (has_palette) {
int i; int i;
int palette_size; int palette_size;
png_color *palette; png_color *palette;
@ -79,11 +81,11 @@ static void ReadHeightmapPNGImageData(byte *map, png_structp png_ptr, png_infop
for (x = 0; x < png_get_image_width(png_ptr, info_ptr); x++) { for (x = 0; x < png_get_image_width(png_ptr, info_ptr); x++) {
for (y = 0; y < png_get_image_height(png_ptr, info_ptr); y++) { for (y = 0; y < png_get_image_height(png_ptr, info_ptr); y++) {
byte *pixel = &map[y * png_get_image_width(png_ptr, info_ptr) + x]; byte *pixel = &map[y * png_get_image_width(png_ptr, info_ptr) + x];
uint x_offset = x * png_get_channels(png_ptr, info_ptr); uint x_offset = x * channels;
if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) { if (has_palette) {
*pixel = gray_palette[row_pointers[y][x_offset]]; *pixel = gray_palette[row_pointers[y][x_offset]];
} else if (png_get_channels(png_ptr, info_ptr) == 3) { } else if (channels == 3) {
*pixel = RGBToGrayscale(row_pointers[y][x_offset + 0], *pixel = RGBToGrayscale(row_pointers[y][x_offset + 0],
row_pointers[y][x_offset + 1], row_pointers[y][x_offset + 2]); row_pointers[y][x_offset + 1], row_pointers[y][x_offset + 2]);
} else { } else {

View File

@ -26,7 +26,7 @@
* Create a new socket for the game connection. * Create a new socket for the game connection.
* @param s The socket to connect with. * @param s The socket to connect with.
*/ */
NetworkGameSocketHandler::NetworkGameSocketHandler(SOCKET s) : info(NULL), NetworkGameSocketHandler::NetworkGameSocketHandler(SOCKET s) : info(NULL), client_id(INVALID_CLIENT_ID),
last_frame(_frame_counter), last_frame_server(_frame_counter), last_packet(_realtime_tick) last_frame(_frame_counter), last_frame_server(_frame_counter), last_packet(_realtime_tick)
{ {
this->sock = s; this->sock = s;

View File

@ -155,9 +155,9 @@ bool IsNetworkCompatibleVersion(const char *version);
*/ */
struct CommandPacket : CommandContainer { struct CommandPacket : CommandContainer {
/** Make sure the pointer is NULL. */ /** Make sure the pointer is NULL. */
CommandPacket() : next(NULL) {} CommandPacket() : next(NULL), company(INVALID_COMPANY), frame(0), my_cmd(false) {}
CommandPacket *next; ///< the next command packet (if in queue) CommandPacket *next; ///< the next command packet (if in queue)
CompanyByte company; ///< company that is executing the command CompanyID company; ///< company that is executing the command
uint32 frame; ///< the frame in which this packet is executed uint32 frame; ///< the frame in which this packet is executed
bool my_cmd; ///< did the command originate from "me" bool my_cmd; ///< did the command originate from "me"
}; };

View File

@ -226,7 +226,8 @@ GRFParameterInfo::GRFParameterInfo(uint nr) :
def_value(0), def_value(0),
param_nr(nr), param_nr(nr),
first_bit(0), first_bit(0),
num_bit(32) num_bit(32),
complete_labels(false)
{} {}
/** /**

View File

@ -882,7 +882,7 @@ struct TextRefStack {
byte position; byte position;
bool used; bool used;
TextRefStack() : used(false) {} TextRefStack() : position(0), used(false) {}
TextRefStack(const TextRefStack &stack) : TextRefStack(const TextRefStack &stack) :
position(stack.position), position(stack.position),

View File

@ -349,8 +349,10 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int
static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile) static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
{ {
Order order; /* Hack-ish; unpack order 0, so everything gets initialised with either zero
order.next = NULL; * or a suitable default value for the variable. Then also override the index
* as it is not coming from a pool, so would be initialised. */
Order order(0);
order.index = 0; order.index = 0;
/* check depot first */ /* check depot first */

View File

@ -241,7 +241,7 @@ std::list<CargoPacket *> _packets;
uint32 _num_dests; uint32 _num_dests;
struct FlowSaveLoad { struct FlowSaveLoad {
FlowSaveLoad() : via(0), share(0) {} FlowSaveLoad() : source(0), via(0), share(0), restricted(false) {}
StationID source; StationID source;
StationID via; StationID via;
uint32 share; uint32 share;

View File

@ -32,6 +32,7 @@ static const int MAX_GET_SETTING_OPS = 100000;
class ScriptInfo : public SimpleCountedObject { class ScriptInfo : public SimpleCountedObject {
public: public:
ScriptInfo() : ScriptInfo() :
engine(NULL),
SQ_instance(NULL), SQ_instance(NULL),
main_script(NULL), main_script(NULL),
tar_file(NULL), tar_file(NULL),

View File

@ -49,6 +49,7 @@ static void PrintFunc(bool error_msg, const SQChar *message)
ScriptInstance::ScriptInstance(const char *APIName) : ScriptInstance::ScriptInstance(const char *APIName) :
engine(NULL), engine(NULL),
versionAPI(NULL),
controller(NULL), controller(NULL),
storage(NULL), storage(NULL),
instance(NULL), instance(NULL),

View File

@ -76,6 +76,9 @@ public:
new_vehicle_id (0), new_vehicle_id (0),
new_sign_id (0), new_sign_id (0),
new_group_id (0), new_group_id (0),
new_goal_id (0),
new_story_page_id (0),
new_story_page_element_id(0),
/* calback_value (can't be set) */ /* calback_value (can't be set) */
road_type (INVALID_ROADTYPE), road_type (INVALID_ROADTYPE),
rail_type (INVALID_RAILTYPE), rail_type (INVALID_RAILTYPE),

View File

@ -206,6 +206,7 @@ struct GoodsEntry {
rating(INITIAL_STATION_RATING), rating(INITIAL_STATION_RATING),
last_speed(0), last_speed(0),
last_age(255), last_age(255),
amount_fract(0),
link_graph(INVALID_LINK_GRAPH), link_graph(INVALID_LINK_GRAPH),
node(INVALID_NODE), node(INVALID_NODE),
max_waiting_cargo(0) max_waiting_cargo(0)