From 52252f82b3248a800bcd7a2c3300c0a6665ca72b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Mon, 7 Sep 2015 00:46:54 +0200 Subject: [PATCH] assorted fixes --- src/cmdline_sprite.c | 6 +++--- src/config.c | 4 ++-- src/drawing/string.c | 12 ++++++++---- src/localisation/utf8.c | 1 + src/management/award.c | 2 +- src/peep/peep.c | 6 +++--- src/ride/ride.c | 12 ++++++------ src/ride/track.c | 10 +++++++--- src/util/util.c | 2 +- src/windows/editor_bottom_toolbar.c | 4 ++-- src/windows/loadsave.c | 8 ++++---- src/windows/themes.c | 2 +- 12 files changed, 39 insertions(+), 30 deletions(-) diff --git a/src/cmdline_sprite.c b/src/cmdline_sprite.c index af9a9ea022..80360d2590 100644 --- a/src/cmdline_sprite.c +++ b/src/cmdline_sprite.c @@ -407,8 +407,8 @@ int cmdline_for_sprite(const char **argv, int argc) return -1; } - printf("sprites: %d\n", spriteFileHeader.num_entries); - printf("data size: %d\n", spriteFileHeader.total_size); + printf("sprites: %lu\n", spriteFileHeader.num_entries); + printf("data size: %lu\n", spriteFileHeader.total_size); sprite_file_close(); return 1; @@ -432,7 +432,7 @@ int cmdline_for_sprite(const char **argv, int argc) printf("height: %d\n", g1->height); printf("x offset: %d\n", g1->x_offset); printf("y offset: %d\n", g1->y_offset); - printf("data offset: 0x%X\n", (uint32)g1->offset); + printf("data offset: 0x%lX\n", (uint32)g1->offset); sprite_file_close(); return 1; diff --git a/src/config.c b/src/config.c index cd6219d53d..b69ac071f7 100644 --- a/src/config.c +++ b/src/config.c @@ -471,7 +471,7 @@ static void config_save_property_value(SDL_RWops *file, uint8 type, value_union rwopsprintf(file, "%u", value->value_uint16); break; case CONFIG_VALUE_TYPE_UINT32: - rwopsprintf(file, "%u", value->value_uint32); + rwopsprintf(file, "%lu", value->value_uint32); break; case CONFIG_VALUE_TYPE_SINT8: rwopsprintf(file, "%d", value->value_sint8); @@ -480,7 +480,7 @@ static void config_save_property_value(SDL_RWops *file, uint8 type, value_union rwopsprintf(file, "%d", value->value_sint16); break; case CONFIG_VALUE_TYPE_SINT32: - rwopsprintf(file, "%d", value->value_sint32); + rwopsprintf(file, "%ld", value->value_sint32); break; case CONFIG_VALUE_TYPE_FLOAT: rwopsprintf(file, "%.3f", value->value_float); diff --git a/src/drawing/string.c b/src/drawing/string.c index e495959634..d73f91ee3f 100644 --- a/src/drawing/string.c +++ b/src/drawing/string.c @@ -275,7 +275,7 @@ void gfx_draw_string_left_clipped(rct_drawpixelinfo* dpi, int format, void* args void gfx_draw_string_centred_clipped(rct_drawpixelinfo *dpi, int format, void *args, int colour, int x, int y, int width) { char* buffer; - short text_width; + int text_width; buffer = RCT2_ADDRESS(RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER, char); format_string(buffer, format, args); @@ -286,9 +286,11 @@ void gfx_draw_string_centred_clipped(rct_drawpixelinfo *dpi, int format, void *a text_width = gfx_clip_string(buffer, width); // Draw the text centred - if (text_width <= 0xFFFF) { + if (text_width <= 0xFFFF && text_width >= 0) { x -= (text_width - 1) / 2; gfx_draw_string(dpi, buffer, colour, x, y); + } else { + log_warning("improper text width %d for string %s", text_width, buffer); } } @@ -331,7 +333,7 @@ void gfx_draw_string_right(rct_drawpixelinfo* dpi, int format, void* args, int c void gfx_draw_string_centred(rct_drawpixelinfo *dpi, int format, int x, int y, int colour, void *args) { char* buffer; - short text_width; + int text_width; buffer = RCT2_ADDRESS(RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER, char); format_string(buffer, format, args); @@ -342,9 +344,11 @@ void gfx_draw_string_centred(rct_drawpixelinfo *dpi, int format, int x, int y, i text_width = gfx_get_string_width(buffer); // Draw the text centred - if (text_width <= 0xFFFF) { + if (text_width <= 0xFFFF && text_width >= 0) { x -= text_width / 2; gfx_draw_string(dpi, buffer, colour, x, y); + } else { + log_warning("improper text width %d for string %s", text_width, buffer); } } diff --git a/src/localisation/utf8.c b/src/localisation/utf8.c index 9f6763e01e..e6403e1399 100644 --- a/src/localisation/utf8.c +++ b/src/localisation/utf8.c @@ -1,4 +1,5 @@ #include "localisation.h" +#include uint32 utf8_get_next(const utf8 *char_ptr, const utf8 **nextchar_ptr) { diff --git a/src/management/award.c b/src/management/award.c index 4c025f28aa..d2ec346818 100644 --- a/src/management/award.c +++ b/src/management/award.c @@ -414,7 +414,7 @@ static int award_is_deserved_most_disappointing(int awardType, int activeAwardTy disappointingRides = 0; FOR_ALL_RIDES(i, ride) { - if (ride->excitement == 0xFFFF || ride->popularity == 0xFF) + if (ride->excitement == (ride_rating)0xFFFF || ride->popularity == 0xFF) continue; countedRides++; diff --git a/src/peep/peep.c b/src/peep/peep.c index 2c87a5f3c7..0ac27206f2 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -5394,7 +5394,7 @@ rct_peep *peep_generate(int x, int y, int z) cash = 0; } - if (RCT2_GLOBAL(RCT2_ADDRESS_GUEST_INITIAL_CASH, money16) == 0xFFFF){ + if (RCT2_GLOBAL(RCT2_ADDRESS_GUEST_INITIAL_CASH, money16) == (money16)0xFFFF){ cash = 0; } @@ -7030,7 +7030,7 @@ static int guest_path_find_leaving_park(rct_peep *peep, rct_map_element *map_ele RCT2_GLOBAL(0x00F1AEE0, uint8) = 1; RCT2_GLOBAL(0x00F1AEE1, uint8) = 0xFF; direction = sub_69A5F0(peep->next_x, peep->next_y, peep->next_z, peep, map_element); - if (direction == -1) + if (direction == 0xFF) return guest_path_find_aimless(peep, edges); else return peep_move_one_tile(direction, peep); @@ -8003,7 +8003,7 @@ static bool sub_6960AB(rct_peep *peep, int rideIndex, int dh, int bp) goto loc_696658; } } - if (ride->excitement != 0xFFFF) { + if (ride->excitement != (ride_rating)0xFFFF) { if (rideIndex == peep->guest_heading_to_ride_id) { if (ride->intensity > RIDE_RATING(10, 00) && !gConfigCheat.ignore_ride_intensity) goto loc_6965F1; goto loc_696387; diff --git a/src/ride/ride.c b/src/ride/ride.c index 60d326c961..2ba23f6f94 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -2989,9 +2989,9 @@ static void ride_entrance_exit_connected(rct_ride* ride, int ride_idx) entrance = ride->entrances[i], exit = ride->exits[i]; - if (station_start == -1 ) + if (station_start == 0xFFFF ) continue; - if (entrance != -1 && !ride_entrance_exit_is_reachable(entrance, ride, i)) { + if (entrance != 0xFFFF && !ride_entrance_exit_is_reachable(entrance, ride, i)) { // name of ride is parameter of the format string RCT2_GLOBAL(0x013CE952, uint16) = ride->name; RCT2_GLOBAL(0x013CE954, uint32) = ride->name_arguments; @@ -2999,7 +2999,7 @@ static void ride_entrance_exit_connected(rct_ride* ride, int ride_idx) ride->connected_message_throttle = 3; } - if (exit != -1 && !ride_entrance_exit_is_reachable(exit, ride, i)) { + if (exit != 0xFFFF && !ride_entrance_exit_is_reachable(exit, ride, i)) { // name of ride is parameter of the format string RCT2_GLOBAL(0x013CE952, uint16) = ride->name; RCT2_GLOBAL(0x013CE954, uint32) = ride->name_arguments; @@ -5222,17 +5222,17 @@ void game_command_demolish_ride(int *eax, int *ebx, int *ecx, int *edx, int *esi peep->item_standard_flags &= ~PEEP_ITEM_PHOTO; } } - if(peep->item_extra_flags && PEEP_ITEM_PHOTO2){ + if(peep->item_extra_flags & PEEP_ITEM_PHOTO2){ if(peep->photo2_ride_ref == ride_id){ peep->item_extra_flags &= ~PEEP_ITEM_PHOTO2; } } - if(peep->item_extra_flags && PEEP_ITEM_PHOTO3){ + if(peep->item_extra_flags & PEEP_ITEM_PHOTO3){ if(peep->photo3_ride_ref == ride_id){ peep->item_extra_flags &= ~PEEP_ITEM_PHOTO3; } } - if(peep->item_extra_flags && PEEP_ITEM_PHOTO4){ + if(peep->item_extra_flags & PEEP_ITEM_PHOTO4){ if(peep->photo4_ride_ref == ride_id){ peep->item_extra_flags &= ~PEEP_ITEM_PHOTO4; } diff --git a/src/ride/track.c b/src/ride/track.c index 73e5cfde9e..7018fe4e4c 100644 --- a/src/ride/track.c +++ b/src/ride/track.c @@ -543,7 +543,11 @@ rct_track_td6* load_track_design(const char *path) // Decode the track data decoded = malloc(0x10000); decodedLength = sawyercoding_decode_td6(fpBuffer, decoded, fpLength); - realloc(decoded, decodedLength); + decoded = realloc(decoded, decodedLength); + if (decoded == NULL) { + log_error("failed to realloc"); + return 0; + } free(fpBuffer); rct_track_td6* track_design = RCT2_ADDRESS(0x009D8178, rct_track_td6); @@ -2733,7 +2737,7 @@ int tracked_ride_to_td6(uint8 rideIndex, rct_track_td6* track_design, uint8* tra bh = trackElement.element->properties.track.colour >> 4; } - uint8 flags = trackElement.element->type & (1 << 7) | bh; + uint8 flags = (trackElement.element->type & (1 << 7)) | bh; flags |= (trackElement.element->properties.track.colour & 3) << 4; if (RCT2_ADDRESS(0x0097D4F2, uint16)[ride->type * 4] & (1 << 3) && @@ -2990,7 +2994,7 @@ int save_track_design(uint8 rideIndex){ return 0; } - if (ride->ratings.excitement == 0xFFFF){ + if (ride->ratings.excitement == (ride_rating)0xFFFF){ window_error_open(STR_CANT_SAVE_TRACK_DESIGN, RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TEXT, rct_string_id)); return 0; } diff --git a/src/util/util.c b/src/util/util.c index d5e8c39b4d..f96fa54731 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -185,4 +185,4 @@ bool utf8_is_bom(const char *str) bool str_is_null_or_empty(const char *str) { return str == NULL || str[0] == 0; -} \ No newline at end of file +} diff --git a/src/windows/editor_bottom_toolbar.c b/src/windows/editor_bottom_toolbar.c index 62a55efa6d..3874d0b05a 100644 --- a/src/windows/editor_bottom_toolbar.c +++ b/src/windows/editor_bottom_toolbar.c @@ -400,7 +400,7 @@ static void window_editor_bottom_toolbar_mouseup(rct_window *w, int widgetIndex) { if (widgetIndex == WIDX_PREVIOUS_STEP_BUTTON) { if ((RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & SCREEN_FLAGS_TRACK_DESIGNER) || - RCT2_GLOBAL(0x13573C8, uint16) == 0x2710 && !(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_18)) { + (RCT2_GLOBAL(0x13573C8, uint16) == 0x2710 && !(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_18))) { previous_button_mouseup_events[g_editor_step](); } } else if (widgetIndex == WIDX_NEXT_STEP_BUTTON) { @@ -573,4 +573,4 @@ void window_editor_bottom_toolbar_paint(rct_window *w, rct_drawpixelinfo *dpi) } } -} \ No newline at end of file +} diff --git a/src/windows/loadsave.c b/src/windows/loadsave.c index f6930b2ad9..17622d1f1d 100644 --- a/src/windows/loadsave.c +++ b/src/windows/loadsave.c @@ -429,8 +429,8 @@ static void window_loadsave_textinput(rct_window *w, int widgetIndex, char *text } strncpy(path, _directory, sizeof(path)); - strncat(path, text, sizeof(path)); - strncat(path, _extension, sizeof(path)); + strncat(path, text, sizeof(path) - strnlen(path, MAX_PATH) - 1); + strncat(path, _extension, sizeof(path) - strnlen(path, MAX_PATH) - 1); overwrite = 0; for (i = 0; i < _listItemsCount; i++) { @@ -604,8 +604,8 @@ static void window_loadsave_populate_list(int includeNewItem, bool browsable, co _shortenedDirectory[0] = '\0'; strncpy(filter, directory, sizeof(filter)); - strncat(filter, "*", sizeof(filter)); - strncat(filter, extension, sizeof(filter)); + strncat(filter, "*", sizeof(filter) - strnlen(filter, MAX_PATH) - 1); + strncat(filter, extension, sizeof(filter) - strnlen(filter, MAX_PATH) - 1); if (_listItems != NULL) free(_listItems); diff --git a/src/windows/themes.c b/src/windows/themes.c index 11e2a8aee4..3c51d80887 100644 --- a/src/windows/themes.c +++ b/src/windows/themes.c @@ -595,7 +595,7 @@ static void window_themes_dropdown(rct_window *w, int widgetIndex, int dropdownI switch (widgetIndex) { case WIDX_THEMES_LIST: if (dropdownIndex != -1) { - get_colour_scheme_tab()->colours[_color_index_2] = dropdownIndex | get_colour_scheme_tab()->colours[_color_index_2] & 0x80; + get_colour_scheme_tab()->colours[_color_index_2] = dropdownIndex | (get_colour_scheme_tab()->colours[_color_index_2] & 0x80); window_invalidate_all(); _color_index_1 = -1; _color_index_2 = -1;