diff --git a/libticonv/trunk/src/Makefile.am b/libticonv/trunk/src/Makefile.am index b97dbba4..6858532d 100644 --- a/libticonv/trunk/src/Makefile.am +++ b/libticonv/trunk/src/Makefile.am @@ -32,4 +32,5 @@ if OS_MAC libticonv_la_LDFLAGS += -L/usr/local/opt/libiconv/lib/ libticonv_la_LIBADD += -liconv endif + libticonv_la_CPPFLAGS += -DUSE_ICONV endif \ No newline at end of file diff --git a/libticonv/trunk/src/charset.cc b/libticonv/trunk/src/charset.cc index 45c897fb..3dc15cb2 100644 --- a/libticonv/trunk/src/charset.cc +++ b/libticonv/trunk/src/charset.cc @@ -127,14 +127,14 @@ static char * ticonv_utf16_to_nonusb(const unsigned long * charset, const unsign p++; } - *(q++) = c; + *(q++) = (unsigned char)c; // c < 256 if we come here... } else { *q = '?'; for (unsigned int i = 0; i < 256; i++) { if (charset[i] == c) { - *q = i; + *q = (unsigned char)i; break; } } diff --git a/libticonv/trunk/src/filename.cc b/libticonv/trunk/src/filename.cc index 2e86cedf..1cdb874b 100644 --- a/libticonv/trunk/src/filename.cc +++ b/libticonv/trunk/src/filename.cc @@ -57,7 +57,7 @@ char* TICALL ticonv_utf16_to_gfe(CalcModel model, const unsigned short *src) { const int is_utf8 = ticonv_environment_is_utf8(); const char *str; - unsigned short *utf16_src; + const unsigned short *utf16_src; unsigned short *utf16_dst; char *dst; @@ -67,7 +67,7 @@ char* TICALL ticonv_utf16_to_gfe(CalcModel model, const unsigned short *src) } // detokenization to UTF-16 - unsigned short* p = utf16_src = (unsigned short*)src; + const unsigned short* p = utf16_src = src; unsigned short* q = utf16_dst = (unsigned short*)g_malloc0(18 * ticonv_utf16_strlen(utf16_src) + 2); // conversion from UTF-16 to UTF-16 @@ -136,7 +136,7 @@ char* TICALL ticonv_utf16_to_gfe(CalcModel model, const unsigned short *src) { if (*p >= 0x2080 && *p <= 0x2089) { - *q++ = (*p++ - 0x2080) + '0'; + *q++ = (unsigned short)((*p++ - 0x2080) + '0'); } else { @@ -243,7 +243,7 @@ void TICALL ticonv_gfe_free(char *src) **/ char* TICALL ticonv_gfe_to_zfe(CalcModel model, const char *src_) { - char *src; + const char *src; char *dst; if (src_ == nullptr) @@ -256,7 +256,7 @@ char* TICALL ticonv_gfe_to_zfe(CalcModel model, const char *src_) // ticonv_utf16_to_gfe. if (!ticonv_environment_has_utf8_filenames()) return g_strdup(src_); - const char* p = src = (char*)src_; + const char* p = src = src_; char* q = dst = (char*)g_malloc0(18 * strlen(src) + 1); while(*p) diff --git a/libticonv/trunk/src/ticonv.cc b/libticonv/trunk/src/ticonv.cc index 02041d97..a9fbae0a 100644 --- a/libticonv/trunk/src/ticonv.cc +++ b/libticonv/trunk/src/ticonv.cc @@ -221,13 +221,15 @@ char* TICALL ticonv_charset_utf16_to_ti_s(CalcModel model, const unsigned short return ti; } break; + case CALC_NONE: case CALC_TIPRESENTER: - default: { ti[0] = 0; return ti; } break; + case CALC_MAX: + default: return nullptr; break; } } else @@ -343,8 +345,10 @@ unsigned short* TICALL ticonv_charset_ti_to_utf16_s(CalcModel model, const char return utf16; } break; + case CALC_NONE: case CALC_TIPRESENTER: default: utf16[0] = 0; return utf16; + case CALC_MAX: return nullptr; break; } } else @@ -1284,6 +1288,8 @@ CalcProductIDs TICALL ticonv_model_to_product_id(CalcModel model) case CALC_CBR2: return PRODUCT_ID_NONE; case CALC_LABPRO: return PRODUCT_ID_LABPRO; case CALC_TIPRESENTER: return PRODUCT_ID_TIPRESENTER; + case CALC_NONE: + case CALC_MAX: default: return PRODUCT_ID_NONE; } } diff --git a/libticonv/trunk/src/tokens.cc b/libticonv/trunk/src/tokens.cc index 89d3662a..deb4689a 100644 --- a/libticonv/trunk/src/tokens.cc +++ b/libticonv/trunk/src/tokens.cc @@ -150,6 +150,7 @@ static char *detokenize_vartype(CalcModel model, const char *src, unsigned char case CALC_CBR2: case CALC_LABPRO: case CALC_TIPRESENTER: + case CALC_MAX: default: break; } @@ -172,7 +173,7 @@ static char *detokenize_varname(CalcModel model, const char *src, unsigned char { if (tok2 != 0x09) { - dst = g_strdup_printf("Image%d", tok2 + 1); + dst = g_strdup_printf("Image%u", tok2 + 1); } else { @@ -335,11 +336,11 @@ static char *detokenize_varname(CalcModel model, const char *src, unsigned char case 0x60: /* Pictures */ if (model == CALC_TI73) { - dst = g_strdup_printf("Pic%d", tok2); + dst = g_strdup_printf("Pic%u", tok2); } else if (tok2 != 0x09) { - dst = g_strdup_printf("Pic%d", tok2 + 1); + dst = g_strdup_printf("Pic%u", tok2 + 1); } else { @@ -350,11 +351,11 @@ static char *detokenize_varname(CalcModel model, const char *src, unsigned char case 0x61: /* GDB */ if (model == CALC_TI73) { - dst = g_strdup_printf("GDB%d", tok2); + dst = g_strdup_printf("GDB%u", tok2); } else if (tok2 != 0x09) { - dst = g_strdup_printf("GDB%d", tok2 + 1); + dst = g_strdup_printf("GDB%u", tok2 + 1); } else { @@ -489,11 +490,11 @@ static char *detokenize_varname(CalcModel model, const char *src, unsigned char case 0xAA: if (model == CALC_TI73) { - dst = g_strdup_printf("Str%d", tok2); + dst = g_strdup_printf("Str%u", tok2); } else if (tok2 != 0x09) { - dst = g_strdup_printf("Str%d", tok2 + 1); + dst = g_strdup_printf("Str%u", tok2 + 1); } else { @@ -555,6 +556,7 @@ char* TICALL ticonv_varname_detokenize(CalcModel model, const char *src, unsigne { return dst; } + return g_strdup(src); case CALC_TI89: case CALC_TI89T: case CALC_TI92: @@ -588,6 +590,7 @@ char* TICALL ticonv_varname_detokenize(CalcModel model, const char *src, unsigne case CALC_NONE: case CALC_TI80: case CALC_TIPRESENTER: + case CALC_MAX: default: return g_strdup("________"); } @@ -720,6 +723,7 @@ char* TICALL ticonv_varname_tokenize(CalcModel model, const char *src_, unsigned case CALC_CBR2: case CALC_LABPRO: case CALC_TIPRESENTER: + case CALC_MAX: default: break; } diff --git a/libticonv/trunk/src/type2str.cc b/libticonv/trunk/src/type2str.cc index b456c52f..28290542 100644 --- a/libticonv/trunk/src/type2str.cc +++ b/libticonv/trunk/src/type2str.cc @@ -80,6 +80,7 @@ const char * TICALL ticonv_model_to_string(CalcModel model) case CALC_CBR2: return "CBR2"; case CALC_LABPRO: return "LabPro"; case CALC_TIPRESENTER: return "TI-Presenter"; + case CALC_MAX: default: return "unknown"; } } diff --git a/libticonv/trunk/tests/test_ticonv.cc b/libticonv/trunk/tests/test_ticonv.cc index b2c4c8b4..43d3d960 100644 --- a/libticonv/trunk/tests/test_ticonv.cc +++ b/libticonv/trunk/tests/test_ticonv.cc @@ -74,7 +74,7 @@ int main(int argc, char **argv) printf(" 0 1 2 3 4 5 6 7 8 9 A B C D E F\n"); - for(int i = 0; i < 16; i++) + for (unsigned int i = 0; i < 16; i++) { printf("%x ", i); for(int j = 0; j < 16; j++) diff --git a/libticonv/trunk/tests/torture_ticonv.c b/libticonv/trunk/tests/torture_ticonv.c index 87eaab22..92af2e55 100644 --- a/libticonv/trunk/tests/torture_ticonv.c +++ b/libticonv/trunk/tests/torture_ticonv.c @@ -14,7 +14,8 @@ fprintf(stderr, "%d\t" TYPE "\n", __LINE__, FUNCTION(__VA_ARGS__)) FUNCTION(__VA_ARGS__); fprintf(stderr, "%d\n", __LINE__) #define INT "%d" -#define SIZE "%zd" +#define UINT "%u" +#define SIZE "%zu" #define PTR "%p" #define STR "\"%s\"" @@ -84,7 +85,7 @@ int main(int argc, char **argv) PRINTF(ticonv_model_has_real_screen, INT, CALC_NONE); PRINTF(ticonv_model_has_monochrome_screen, INT, CALC_NONE); PRINTF(ticonv_model_has_color_screen, INT, CALC_NONE); - PRINTF(ticonv_model_to_product_id, INT, CALC_NONE); + PRINTF(ticonv_model_to_product_id, UINT, CALC_NONE); PRINTF(ticonv_varname_to_utf16_s, PTR, -1, NULL, (void *)0x12345678, 0); PRINTF(ticonv_varname_to_utf16_s, PTR, -1, (void *)0x12345678, NULL, 0); PRINTF(ticonv_varname_to_utf16, PTR, -1, NULL, 0); @@ -112,7 +113,7 @@ int main(int argc, char **argv) PRINTF(ticonv_varname_from_tifile, STR, -1, NULL, 0); PRINTF(ticonv_model_to_string, STR, CALC_NONE); - PRINTF(ticonv_string_to_model, INT, NULL); + PRINTF(ticonv_string_to_model, UINT, NULL); fprintf(stderr, "%d\t%p\n", __LINE__, ti73_charset); fprintf(stderr, "%d\t%p\n", __LINE__, ti80_charset); fprintf(stderr, "%d\t%p\n", __LINE__, ti82_charset); diff --git a/libtifiles/trunk/configure.ac b/libtifiles/trunk/configure.ac index b7992f83..6c652f9d 100644 --- a/libtifiles/trunk/configure.ac +++ b/libtifiles/trunk/configure.ac @@ -80,7 +80,6 @@ AC_CHECK_HEADERS([inttypes.h stdint.h stdlib.h string.h]) # Checks for typedefs, structures, and compiler characteristics. AC_C_CONST -AC_C_RESTRICT AC_TYPE_SIZE_T AC_STRUCT_TM diff --git a/libtifiles/trunk/src/cert.cc b/libtifiles/trunk/src/cert.cc index 7e3dd8c4..ce6c878d 100644 --- a/libtifiles/trunk/src/cert.cc +++ b/libtifiles/trunk/src/cert.cc @@ -59,7 +59,7 @@ int TICALL tifiles_cert_field_get(const uint8_t *data, uint32_t length, uint16_t } // Retrieve field ID and number of additional bytes we need to read for the field's size. - const uint16_t field_id = (((uint16_t)data[0]) << 8) | data[1]; + const uint16_t field_id = (((uint16_t)data[0]) << 8) | (uint16_t)data[1]; switch (field_id & 0xF) { case 0xD: additional_len = 1; break; @@ -145,7 +145,7 @@ int TICALL tifiles_cert_field_next(const uint8_t **data, uint32_t *length) const int ret = tifiles_cert_field_get(*data, *length, nullptr, &contents, &field_size); if (!ret) { - *length -= contents + field_size - *data; + *length -= (uint32_t)((contents + field_size) - *data); *data = contents + field_size; } diff --git a/libtifiles/trunk/src/files8x.cc b/libtifiles/trunk/src/files8x.cc index aeb2c48d..da5019d9 100644 --- a/libtifiles/trunk/src/files8x.cc +++ b/libtifiles/trunk/src/files8x.cc @@ -65,33 +65,33 @@ static int is_ti83p(CalcModel model) static uint16_t compute_backup_sum(BackupContent* content, uint16_t header_size) { - uint16_t sum= 0; + uint16_t sum = 0; sum += header_size; - sum += tifiles_checksum((uint8_t *)&(content->data_length1), 2); + sum += tifiles_checksum((uint8_t *)&(content->data_length1), 2U); sum += content->type; if (header_size >= 12) { sum += content->version; } - sum += tifiles_checksum((uint8_t *)&(content->data_length2), 2); - sum += tifiles_checksum((uint8_t *)&(content->data_length3), 2); + sum += tifiles_checksum((uint8_t *)&(content->data_length2), 2U); + sum += tifiles_checksum((uint8_t *)&(content->data_length3), 2U); if (content->model != CALC_TI86) { - sum += tifiles_checksum((uint8_t *)&(content->mem_address), 2); + sum += tifiles_checksum((uint8_t *)&(content->mem_address), 2U); } else { - sum += tifiles_checksum((uint8_t *)&(content->data_length4), 2); + sum += tifiles_checksum((uint8_t *)&(content->data_length4), 2U); } - sum += tifiles_checksum((uint8_t *)&(content->data_length1), 2); + sum += tifiles_checksum((uint8_t *)&(content->data_length1), 2U); sum += tifiles_checksum(content->data_part1, content->data_length1); - sum += tifiles_checksum((uint8_t *)&(content->data_length2), 2); + sum += tifiles_checksum((uint8_t *)&(content->data_length2), 2U); sum += tifiles_checksum(content->data_part2, content->data_length2); - sum += tifiles_checksum((uint8_t *)&(content->data_length3), 2); + sum += tifiles_checksum((uint8_t *)&(content->data_length3), 2U); sum += tifiles_checksum(content->data_part3, content->data_length3); - sum += tifiles_checksum((uint8_t *)&(content->data_length4), 2); + sum += tifiles_checksum((uint8_t *)&(content->data_length4), 2U); sum += tifiles_checksum(content->data_part4, content->data_length4); return sum; @@ -295,7 +295,7 @@ int ti8x_file_read_regular(const char *filename, Ti8xRegular *content) { for (unsigned int j = 0; j < 8U - name_length; j++) { - sum += fgetc(f); + sum += (uint8_t)fgetc(f); } } if (ti83p_flag) @@ -312,7 +312,7 @@ int ti8x_file_read_regular(const char *filename, Ti8xRegular *content) else { entry->attr = ((attribute & 0x8000) ? ATTRB_ARCHIVED : ATTRB_NONE); - entry->version = attribute & 0xff; + entry->version = (uint8_t)(attribute & 0xff); } // Handle broken 84+CSE Pic files created by older versions of libtifiles. @@ -336,15 +336,15 @@ int ti8x_file_read_regular(const char *filename, Ti8xRegular *content) if (fread(entry->data, 1, entry->size, f) < entry->size) goto tfrr; sum += packet_length; - sum += tifiles_checksum((uint8_t *)&(entry->size), 2); + sum += tifiles_checksum((uint8_t *)&(entry->size), 2U); sum += entry->type; if (is_ti8586(content->model)) { - sum += strlen(entry->name); + sum += (uint16_t)strlen(entry->name); } sum += tifiles_checksum((uint8_t *)varname, name_length); sum += 0; // see above (file may be padded with garbage) - sum += tifiles_checksum((uint8_t *)&(entry->size), 2); + sum += tifiles_checksum((uint8_t *)&(entry->size), 2U); sum += tifiles_checksum(entry->data, entry->size); } @@ -575,7 +575,7 @@ static int check_data_type(uint8_t id) return 0; } -static int get_native_app_name(const FlashContent *content, char *buffer, size_t buffer_size) +static int get_native_app_name(const FlashContent *content, char *buffer, uint32_t buffer_size) { const uint8_t *data, *name; uint32_t size, n; @@ -859,7 +859,7 @@ int ti8x_file_write_regular(const char *fname, Ti8xRegular *content, char **real const VarEntry *entry = content->entries[i]; if (entry == nullptr) { - tifiles_warning("%s: skipping null content entry %d", __FUNCTION__, i); + tifiles_warning("%s: skipping null content entry %u", __FUNCTION__, i); continue; } @@ -873,7 +873,7 @@ int ti8x_file_write_regular(const char *fname, Ti8xRegular *content, char **real } else if (content->model == CALC_TI85) { - data_length += entry->size + 8 + strlen(entry->name); + data_length += entry->size + 8 + (uint32_t)strlen(entry->name); } else if (content->model == CALC_TI86) { @@ -941,7 +941,7 @@ int ti8x_file_write_regular(const char *fname, Ti8xRegular *content, char **real if (content->model == CALC_TI85) { - packet_length = 4 + strlen(entry->name); //offset to data length + packet_length = 4 + (uint16_t)strlen(entry->name); //offset to data length } else if (content->model == CALC_TI86) { @@ -963,7 +963,7 @@ int ti8x_file_write_regular(const char *fname, Ti8xRegular *content, char **real ticonv_varname_to_tifile_sn(content->model_dst, entry->name, varname, sizeof(varname), entry->type); if (is_ti8586(content->model)) { - name_length = strlen(varname); + name_length = (uint8_t)strlen(varname); if (fwrite_byte(f, (uint8_t)name_length) < 0) goto tfwr; if (content->model == CALC_TI85) { @@ -980,7 +980,7 @@ int ti8x_file_write_regular(const char *fname, Ti8xRegular *content, char **real } if (is_ti83p(content->model)) { - const uint16_t attr = (uint16_t)((entry->attr == ATTRB_ARCHIVED) ? 0x8000 : 0x00) + entry->version; + const uint16_t attr = (uint16_t)((entry->attr == ATTRB_ARCHIVED) ? 0x8000U : 0U) + (uint16_t)entry->version; if (fwrite_word(f, attr) < 0) goto tfwr; sum += MSB(attr); sum += LSB(attr); @@ -994,12 +994,12 @@ int ti8x_file_write_regular(const char *fname, Ti8xRegular *content, char **real sum += entry->type; if (is_ti8586(content->model)) { - sum += strlen(entry->name); + sum += (uint16_t)strlen(entry->name); } sum += tifiles_checksum((uint8_t *)varname, name_length); if (content->model == CALC_TI86) { - sum += (8 - name_length) * ' '; + sum += (uint16_t)((8U - name_length) * ' '); } sum += MSB(entry->size); sum += LSB(entry->size); @@ -1061,7 +1061,7 @@ int ti8x_file_write_backup(const char *filename, Ti8xBackup *content) if (fwrite_8_chars(f, tifiles_calctype2signature(content->model)) < 0) goto tfwb; if (fwrite(content->model == CALC_TI85 ? fsignature85 : fsignature8x, 1, 3, f) < 3) goto tfwb; if (fwrite_n_bytes(f, 42, (uint8_t *)content->comment) < 0) goto tfwb; - if (fwrite_word(f, data_length) < 0) goto tfwb; + if (fwrite_word(f, (uint16_t)data_length) < 0) goto tfwb; // Use the old-style header for versions 0 to 5 (84+ OS 2.48 and // earlier), for compatibility with older versions of libtifiles @@ -1245,7 +1245,7 @@ int ti8x_file_write_flash(const char *fname, Ti8xFlash *head, char **real_fname) { int extra_bytes = 0; - uint32_t page_length = content->pages[i]->size; + uint16_t page_length = content->pages[i]->size; if ( content->data_type == TI83p_APPL && i == content->num_pages - 1 && content->pages[0]->data[0] == 0x80 && content->pages[0]->data[1] == 0x0f) @@ -1270,7 +1270,7 @@ int ti8x_file_write_flash(const char *fname, Ti8xFlash *head, char **real_fname) page_length--; } - extra_bytes = app_length + 96 - i * 0x4000 - page_length; + extra_bytes = (int)app_length + 96 - i * 0x4000 - page_length; /* don't add padding beyond the end of the page */ if (page_length + extra_bytes >= 0x3fff) @@ -1291,7 +1291,7 @@ int ti8x_file_write_flash(const char *fname, Ti8xFlash *head, char **real_fname) bytes_written += hex_block_write(f, page_length, content->pages[i]->addr, content->pages[i]->flag, content->pages[i]->data, - content->pages[i]->page, extra_bytes); + content->pages[i]->page, (uint16_t)extra_bytes); // 0 <= extra_bytes <= 96, per the above. } // final block @@ -1341,7 +1341,7 @@ int ti8x_content_display_backup(Ti8xBackup *content) } tifiles_info("BackupContent for TI-8x: %p", content); - tifiles_info("Model: %02X (%u)", content->model, content->model); + tifiles_info("Model: %02X (%d)", (unsigned int)content->model, content->model); tifiles_info("Signature: %s", tifiles_calctype2signature(content->model)); tifiles_info("Comment: %s", content->comment); tifiles_info("Type: %02X (%s)", content->type, tifiles_vartype2string(content->model, content->type)); @@ -1379,9 +1379,9 @@ int ti8x_content_display_flash(Ti8xFlash *content) for (Ti8xFlash* ptr = content; ptr != nullptr; ptr = ptr->next) { tifiles_info("FlashContent for TI-8x: %p", ptr); - tifiles_info("Model: %02X (%u)", ptr->model, ptr->model); + tifiles_info("Model: %02X (%d)", (unsigned int)ptr->model, ptr->model); tifiles_info("Signature: %s", tifiles_calctype2signature(ptr->model)); - tifiles_info("model_dst: %02X (%u)", ptr->model_dst, ptr->model_dst); + tifiles_info("model_dst: %02X (%d)", (unsigned int)ptr->model_dst, ptr->model_dst); tifiles_info("Revision: %u.%u", ptr->revision_major, ptr->revision_minor); tifiles_info("Flags: %02X", ptr->flags); tifiles_info("Object type: %02X", ptr->object_type); @@ -1410,7 +1410,7 @@ int ti8x_content_display_flash(Ti8xFlash *content) tifiles_info("Hardware ID: %02X (%u)", ptr->hw_id, ptr->hw_id); tifiles_info("Length: %08X (%u)", ptr->data_length, ptr->data_length); tifiles_info("Data: %p", ptr->data_part); - tifiles_info("Number of pages: %i", ptr->num_pages); + tifiles_info("Number of pages: %u", ptr->num_pages); tifiles_info("Pages: %p", ptr->pages); tifiles_info("Next: %p", ptr->next); } diff --git a/libtifiles/trunk/src/files9x.cc b/libtifiles/trunk/src/files9x.cc index d4fdf5d5..834cf0c1 100644 --- a/libtifiles/trunk/src/files9x.cc +++ b/libtifiles/trunk/src/files9x.cc @@ -447,6 +447,7 @@ int ti9x_file_read_flash(const char *filename, Ti9xFlash *head) // doesn't have any 'legal' existence. case 8: content->device_type = DEVICE_TYPE_92P; break; // V200PLT case 9: content->device_type = DEVICE_TYPE_89; break; // Titanium + default: break; // content->device_type was already initialized by the memset() above. } content->next = nullptr; @@ -646,7 +647,7 @@ int ti9x_file_write_regular(const char *fname, Ti9xRegular *content, char **real if (fentry == nullptr) { - tifiles_warning("%s: skipping null content entry %d", __FUNCTION__, i); + tifiles_warning("%s: skipping null content entry %u", __FUNCTION__, i); continue; } @@ -876,7 +877,7 @@ int ti9x_content_display_backup(Ti9xBackup *content) } tifiles_info("BackupContent for TI-9x: %p", content); - tifiles_info("Model: %02X (%u)", content->model, content->model); + tifiles_info("Model: %02X (%d)", (unsigned int)content->model, content->model); tifiles_info("Signature: %s", tifiles_calctype2signature(content->model)); tifiles_info("Comment: %s", content->comment); tifiles_info("ROM version: %s", content->rom_version); @@ -903,9 +904,9 @@ int ti9x_content_display_flash(Ti9xFlash *content) for (Ti9xFlash* ptr = content; ptr != nullptr; ptr = ptr->next) { tifiles_info("FlashContent for TI-9x: %p", ptr); - tifiles_info("Model: %02X (%u)", ptr->model, ptr->model); + tifiles_info("Model: %02X (%d)", (unsigned int)ptr->model, ptr->model); tifiles_info("Signature: %s", tifiles_calctype2signature(ptr->model)); - tifiles_info("model_dst: %02X (%u)", ptr->model_dst, ptr->model_dst); + tifiles_info("model_dst: %02X (%d)", (unsigned int)ptr->model_dst, ptr->model_dst); tifiles_info("Revision: %u.%u", ptr->revision_major, ptr->revision_minor); tifiles_info("Flags: %02X", ptr->flags); tifiles_info("Object type: %02X", ptr->object_type); diff --git a/libtifiles/trunk/src/filesnsp.cc b/libtifiles/trunk/src/filesnsp.cc index bb743878..aad34c5e 100644 --- a/libtifiles/trunk/src/filesnsp.cc +++ b/libtifiles/trunk/src/filesnsp.cc @@ -28,6 +28,8 @@ #include #include #include +#define __STDC_FORMAT_MACROS +#include #include #include "tifiles.h" @@ -89,7 +91,7 @@ int tnsp_file_read_regular(const char *filename, FileContent *content) VarEntry *entry = content->entries[0] = (VarEntry *)g_malloc0(sizeof(VarEntry)); gchar *basename = g_path_get_basename(filename); - gchar *ext = tifiles_fext_get(basename); + gchar *ext = const_cast(tifiles_fext_get(basename)); entry->type = tifiles_fext2vartype(content->model, ext); if (ext && ext[0]) *(ext-1) = '\0'; @@ -204,7 +206,7 @@ int tnsp_file_read_flash(const char *filename, FlashContent *content) { goto tfrf; } - content->revision_major = c; + content->revision_major = (uint8_t)c; // Skip char. c = fgetc(f); @@ -219,7 +221,7 @@ int tnsp_file_read_flash(const char *filename, FlashContent *content) { goto tfrf; } - content->revision_minor = c; + content->revision_minor = (uint8_t)c; // Skip chars. c = fgetc(f); @@ -237,7 +239,7 @@ int tnsp_file_read_flash(const char *filename, FlashContent *content) goto tfrf; } } - if (fscanf(f, "%i", &(content->data_length)) < 1) + if (fscanf(f, "%" SCNu32, &(content->data_length)) < 1) { goto tfrf; } @@ -365,16 +367,16 @@ int tnsp_content_display_flash(FlashContent *content) for (ptr = content; ptr != nullptr; ptr = ptr->next) { tifiles_info("FlashContent for TI-Nspire: %p", ptr); - tifiles_info("Model: %02X (%u)", ptr->model, ptr->model); + tifiles_info("Model: %02X (%d)", (unsigned int)ptr->model, ptr->model); tifiles_info("Signature: %s", tifiles_calctype2signature(ptr->model)); - tifiles_info("model_dst: %02X (%u)", ptr->model_dst, ptr->model_dst); + tifiles_info("model_dst: %02X (%d)", (unsigned int)ptr->model_dst, ptr->model_dst); tifiles_info("Revision: %u.%u", ptr->revision_major, ptr->revision_minor); tifiles_info("Flags: %02X", ptr->flags); tifiles_info("Object type: %02X", ptr->object_type); tifiles_info("Date: %02X/%02X/%02X%02X", ptr->revision_day, ptr->revision_month, ptr->revision_year & 0xff, (ptr->revision_year & 0xff00) >> 8); tifiles_info("Name: %s", ptr->name); tifiles_info("Data type: OS data"); - tifiles_info("Length: %08X (%i)", ptr->data_length, ptr->data_length); + tifiles_info("Length: %08X (%" PRIu32 ")", ptr->data_length, ptr->data_length); tifiles_info("Data part: %p", ptr->data_part); tifiles_info("Next: %p", ptr->next); } diff --git a/libtifiles/trunk/src/filesxx.cc b/libtifiles/trunk/src/filesxx.cc index 3292dfea..1048fc5e 100644 --- a/libtifiles/trunk/src/filesxx.cc +++ b/libtifiles/trunk/src/filesxx.cc @@ -297,7 +297,7 @@ int TICALL tifiles_file_display_regular(FileContent *content) return ERR_BAD_CALC; } - tifiles_info("Model: %02X (%u)", content->model, content->model); + tifiles_info("Model: %02X (%d)", (unsigned int)content->model, content->model); tifiles_info("Signature: %s", tifiles_calctype2signature(content->model)); tifiles_info("Comment: %s", content->comment); if (model_supports_folder) @@ -334,7 +334,7 @@ int TICALL tifiles_file_display_regular(FileContent *content) } tifiles_info("Checksum: %04X (%u)", content->checksum, content->checksum); - tifiles_info("Dest model: %02X (%u)", content->model_dst, content->model_dst); + tifiles_info("Dest model: %02X (%d)", (unsigned int)content->model_dst, content->model_dst); return 0; } @@ -545,9 +545,9 @@ FlashContent* TICALL tifiles_content_create_flash(CalcModel model) content->revision_minor = 0; content->flags = 0; content->object_type = 0; - content->revision_day = lt.tm_mday; - content->revision_month = lt.tm_mon; - content->revision_year = lt.tm_year + 1900; + content->revision_day = (uint8_t)lt.tm_mday; + content->revision_month = (uint8_t)lt.tm_mon; + content->revision_year = (uint16_t)(lt.tm_year + 1900); } } diff --git a/libtifiles/trunk/src/filetypes.cc b/libtifiles/trunk/src/filetypes.cc index e50ad2e4..4abab93d 100644 --- a/libtifiles/trunk/src/filetypes.cc +++ b/libtifiles/trunk/src/filetypes.cc @@ -147,6 +147,7 @@ const char * TICALL tifiles_fext_of_group (CalcModel model) case CALC_LABPRO: case CALC_TIPRESENTER: return nullptr; + case CALC_MAX: default: tifiles_critical("%s: invalid model argument", __FUNCTION__); break; @@ -229,6 +230,7 @@ const char * TICALL tifiles_fext_of_backup (CalcModel model) case CALC_LABPRO: case CALC_TIPRESENTER: return nullptr; + case CALC_MAX: default: tifiles_critical("%s: invalid model argument", __FUNCTION__); break; @@ -313,6 +315,7 @@ const char * TICALL tifiles_fext_of_flash_app (CalcModel model) case CALC_LABPRO: case CALC_TIPRESENTER: return nullptr; + case CALC_MAX: default: tifiles_critical("%s: invalid model argument", __FUNCTION__); break; @@ -414,6 +417,7 @@ const char * TICALL tifiles_fext_of_flash_os(CalcModel model) return "c2u"; // .hex is also seen in some OS upgraders. case CALC_TIPRESENTER: return "hex"; // Sbase132.hex from the Windows TI-Presenter OS upgrader. + case CALC_MAX: default: tifiles_critical("%s: invalid model argument", __FUNCTION__); break; @@ -498,6 +502,7 @@ const char * TICALL tifiles_fext_of_certif(CalcModel model) case CALC_LABPRO: case CALC_TIPRESENTER: return nullptr; + case CALC_MAX: default: tifiles_critical("%s: invalid calc_type argument", __FUNCTION__); break; @@ -514,11 +519,11 @@ const char * TICALL tifiles_fext_of_certif(CalcModel model) * * Return value: a file extension without dot as string (like "89g"). **/ -char * TICALL tifiles_fext_get(const char *filename) +const char * TICALL tifiles_fext_get(const char *filename) { if (filename != nullptr) { - char * d = (char *)strrchr(filename, '.'); + const char * d = strrchr(filename, '.'); if (d != nullptr) { return (++d); @@ -529,7 +534,7 @@ char * TICALL tifiles_fext_get(const char *filename) tifiles_critical("%s(NULL)", __FUNCTION__); } - return (char *)""; + return ""; } /** @@ -584,7 +589,7 @@ int TICALL tifiles_file_has_ti_header(const char *filename) { for (char* p = buf; *p != '\0'; p++) { - *p = toupper(*p); + *p = (char)toupper(*p); } if (!strcmp(buf, "**TI73**") || !strcmp(buf, "**TI82**") || @@ -823,7 +828,7 @@ int TICALL tifiles_file_has_tno_header(const char *filename) // Look for a CX II signature, which isn't at the beginning of the file anymore. Sigh. // Sadly, memmem() is not portable. unsigned int remaining = sizeof(str) - 1 - sizeof(TCO2_SIGNATURE) - 1; - char * ptr1 = (char *)memchr(str, 'T', remaining); + const char * ptr1 = (const char *)memchr(str, 'T', remaining); const char * ptr2 = str; while (nullptr != ptr1) { @@ -837,7 +842,7 @@ int TICALL tifiles_file_has_tno_header(const char *filename) break; } ptr2 = ptr1 + 1; - ptr1 = (char *)memchr(ptr2, 'T', remaining); + ptr1 = (const char *)memchr(ptr2, 'T', remaining); } } } diff --git a/libtifiles/trunk/src/intelhex.cc b/libtifiles/trunk/src/intelhex.cc index 6ac3a935..17bd6e15 100644 --- a/libtifiles/trunk/src/intelhex.cc +++ b/libtifiles/trunk/src/intelhex.cc @@ -83,7 +83,7 @@ static int hex_packet_read(FILE *f, uint8_t *size, uint16_t *addr, uint8_t *type int c = fgetc(f); if (c != ':') { - printf("Unexpected char: <%c> = %02X\n", c, c); + printf("Unexpected char: <%c> = %02X\n", c, (unsigned int)c); return -1; } @@ -182,7 +182,7 @@ static int hex_packet_read(FILE *f, uint8_t *size, uint16_t *addr, uint8_t *type */ int hex_block_read(FILE *f, uint16_t *size, uint16_t *addr, uint8_t *type, uint8_t *data, uint16_t *page) { - static int flag = 0x80; + static uint8_t flag = UINT8_C(0x80); static uint16_t flash_page; static uint16_t flash_addr; int new_page = 0; @@ -208,7 +208,7 @@ int hex_block_read(FILE *f, uint16_t *size, uint16_t *addr, uint8_t *type, uint8 *size = 0; // load data - for (int i = 0; i < BLK_MAX; ) + for (uint16_t i = 0; i < BLK_MAX; ) { uint8_t pkt_size, pkt_type; uint8_t pkt_data[PKT_MAX]; @@ -255,7 +255,7 @@ int hex_block_read(FILE *f, uint16_t *size, uint16_t *addr, uint8_t *type, uint8 case HEX_PAGE: // new page - flash_page = (((uint16_t)(pkt_data[0])) << 8) | pkt_data[1]; + flash_page = (((uint16_t)(pkt_data[0])) << 8) | (uint16_t)(pkt_data[1]); new_page = !0; break; @@ -368,8 +368,8 @@ int hex_block_write(FILE *f, uint16_t size, uint16_t addr, uint8_t type, uint8_t } else { - buf[0] = page >> 8; - buf[1] = page & 0xff; + buf[0] = (uint8_t)(page >> 8); + buf[1] = (uint8_t)(page & 0xff); bytes_written += hex_packet_write(f, 2, 0x0000, HEX_PAGE, buf); new_section = 0; } diff --git a/libtifiles/trunk/src/misc.cc b/libtifiles/trunk/src/misc.cc index c51cc3db..81b1b028 100644 --- a/libtifiles/trunk/src/misc.cc +++ b/libtifiles/trunk/src/misc.cc @@ -174,7 +174,7 @@ int TICALL tifiles_hexdump(const uint8_t * ptr, unsigned int len) { const unsigned int alloc_len = (len < 1024) ? len : 1024; - str = (char *)g_malloc(3 * alloc_len + 14); + str = (char *)g_malloc(3 * alloc_len + 19); for (unsigned int i = 0; i < alloc_len; i++) { sprintf(&str[3 * i], "%02X ", ptr[i]); @@ -203,15 +203,15 @@ int TICALL tifiles_hexdump(const uint8_t * ptr, unsigned int len) * * Return value: varname as string. It should not be modified (static). **/ -char *TICALL tifiles_get_varname(const char *full_name) +const char *TICALL tifiles_get_varname(const char *full_name) { if (full_name != nullptr) { - char *bs = (char *)strchr(full_name, '\\'); + const char *bs = strchr(full_name, '\\'); if (bs == nullptr) { - return (char *) full_name; + return full_name; } else { @@ -229,7 +229,7 @@ char *TICALL tifiles_get_varname(const char *full_name) * * Return value: a static string. **/ -char *TICALL tifiles_get_fldname(const char *full_name) +const char *TICALL tifiles_get_fldname(const char *full_name) { static char folder[FLDNAME_MAX]; return tifiles_get_fldname_s(full_name, folder); @@ -244,18 +244,18 @@ char *TICALL tifiles_get_fldname(const char *full_name) * * Return value: the given buffer, dest_fldname. **/ -char *TICALL tifiles_get_fldname_s(const char *full_name, char * dest_fldname) +const char *TICALL tifiles_get_fldname_s(const char *full_name, char * dest_fldname) { if (full_name != nullptr && dest_fldname != nullptr) { - const char *bs = (char *)strchr(full_name, '\\'); + const char *bs = strchr(full_name, '\\'); if (bs == nullptr) { dest_fldname[0] = 0; } else { - const int i = strlen(full_name) - strlen(bs); + const size_t i = strlen(full_name) - strlen(bs); strncpy(dest_fldname, full_name, i); dest_fldname[i] = '\0'; } diff --git a/libtifiles/trunk/src/rwfile.cc b/libtifiles/trunk/src/rwfile.cc index 392d6ef0..7a6d60f5 100644 --- a/libtifiles/trunk/src/rwfile.cc +++ b/libtifiles/trunk/src/rwfile.cc @@ -55,7 +55,7 @@ int fread_n_chars(FILE * f, unsigned int n, char *s) // set NULL terminator s[n] = '\0'; // and set unused bytes to 0 - for (unsigned int i = strlen(s); i < n; i++) + for (size_t i = strlen(s); i < n; i++) { s[i] = '\0'; } @@ -74,7 +74,7 @@ int fwrite_n_chars(FILE * f, unsigned int n, const char *s) { unsigned int i; - const unsigned int l = strlen(s); + const unsigned int l = (unsigned int)strlen(s); if (l > n) { tifiles_critical("string passed to 'fwrite_n_chars' is too long (>n chars).\n"); @@ -111,12 +111,12 @@ int fwrite_n_chars2(FILE * f, unsigned int n, const char *s) { unsigned int i; - const unsigned int l = strlen(s); + const unsigned int l = (unsigned int)strlen(s); if (l > n) { tifiles_critical("string passed to 'fwrite_n_chars2' is too long (>n chars).\n"); tifiles_critical( "s = %s, len(s) = %u\n", s, l); - tifiles_hexdump((uint8_t *)s, (l < n) ? n : l); + tifiles_hexdump((const uint8_t *)s, (l < n) ? n : l); return -1; } diff --git a/libtifiles/trunk/src/tifiles.h b/libtifiles/trunk/src/tifiles.h index d006db52..085af068 100644 --- a/libtifiles/trunk/src/tifiles.h +++ b/libtifiles/trunk/src/tifiles.h @@ -357,7 +357,7 @@ typedef struct TIEXPORT2 const char* TICALL tifiles_fext_of_flash_os (CalcModel model); TIEXPORT2 const char* TICALL tifiles_fext_of_certif (CalcModel model); - TIEXPORT2 char* TICALL tifiles_fext_get (const char *filename); + TIEXPORT2 const char* TICALL tifiles_fext_get (const char *filename); TIEXPORT2 char* TICALL tifiles_fext_dup (const char *filename); TIEXPORT2 void TICALL tifiles_fext_free(char *filename); @@ -421,9 +421,9 @@ typedef struct TIEXPORT2 uint16_t TICALL tifiles_checksum(const uint8_t * buffer, unsigned int size); TIEXPORT2 int TICALL tifiles_hexdump(const uint8_t* ptr, unsigned int length); - TIEXPORT2 char* TICALL tifiles_get_varname(const char *full_name); - TILIBS_DEPRECATED TIEXPORT2 char* TICALL tifiles_get_fldname(const char *full_name); - TIEXPORT2 char* TICALL tifiles_get_fldname_s(const char *full_name, char * dest_fldname); + TIEXPORT2 const char* TICALL tifiles_get_varname(const char *full_name); + TILIBS_DEPRECATED TIEXPORT2 const char* TICALL tifiles_get_fldname(const char *full_name); + TIEXPORT2 const char* TICALL tifiles_get_fldname_s(const char *full_name, char * dest_fldname); TIEXPORT2 char* TICALL tifiles_build_fullname(CalcModel model, char *full_name, const char *fldname, const char *varname); TIEXPORT2 char* TICALL tifiles_build_filename(CalcModel model, const VarEntry *ve); TIEXPORT2 void TICALL tifiles_filename_free(char * filename); diff --git a/libtifiles/trunk/src/tigroup.cc b/libtifiles/trunk/src/tigroup.cc index e5f47dda..3bd97752 100644 --- a/libtifiles/trunk/src/tigroup.cc +++ b/libtifiles/trunk/src/tigroup.cc @@ -154,7 +154,7 @@ int TICALL tifiles_te_display(TigEntry* entry) } tifiles_info("Filename: %s", entry->filename); - tifiles_info("File class: %04X (%u)", entry->type, entry->type); + tifiles_info("File class: %04X (%u)", (unsigned int)entry->type, (unsigned int)entry->type); if (entry->type == TIFILE_FLASH) { @@ -1461,9 +1461,9 @@ int TICALL tifiles_file_display_tigcontent(TigContent *content) return ERR_INVALID_FILE; } - tifiles_info("Model: %02X (%u)", content->model, content->model); + tifiles_info("Model: %02X (%u)", (unsigned int)content->model, (unsigned int)content->model); tifiles_info("Signature: %s", tifiles_calctype2signature(content->model)); - tifiles_info("model_dst: %02X (%u)", content->model_dst, content->model_dst); + tifiles_info("model_dst: %02X (%u)", (unsigned int)content->model_dst, (unsigned int)content->model_dst); tifiles_info("Comment: %s", content->comment); tifiles_info("Compression level: %d", content->comp_level); diff --git a/libtifiles/trunk/src/type2str.cc b/libtifiles/trunk/src/type2str.cc index 8323e917..00f20722 100644 --- a/libtifiles/trunk/src/type2str.cc +++ b/libtifiles/trunk/src/type2str.cc @@ -116,6 +116,7 @@ const char *TICALL tifiles_class_to_string(FileClass klass) case TIFILE_OS: return _("os"); case TIFILE_APP: return _("application"); case TIFILE_FLASH: return _("flash"); + case TIFILE_NONE: default: return _("unknown"); } } diff --git a/libtifiles/trunk/src/types83p.cc b/libtifiles/trunk/src/types83p.cc index b84cbaf5..3bdc267e 100644 --- a/libtifiles/trunk/src/types83p.cc +++ b/libtifiles/trunk/src/types83p.cc @@ -80,7 +80,7 @@ const TI83p_DATA TI83p_CONST[TI83p_MAXTYPES + 1] = {"", "8X?", "8X?", "8X?", "8X?", "8X?", "8X?", "8X?", "Unknown", N_("Unknown")}, // 45, 0x2D {"", "8X?", "8X?", "8X?", "8X?", "8X?", "8X?", "8X?", "Unknown", N_("Unknown")}, {"", "8X?", "8X?", "8X?", "8X?", "8X?", "8X?", "8X?", "Unknown", N_("Unknown")}, - { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr } + { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr } }; #endif diff --git a/libtifiles/trunk/src/typesxx.cc b/libtifiles/trunk/src/typesxx.cc index 8cdb758d..7884d400 100644 --- a/libtifiles/trunk/src/typesxx.cc +++ b/libtifiles/trunk/src/typesxx.cc @@ -110,7 +110,10 @@ const char *TICALL tifiles_vartype2string(CalcModel model, uint8_t data) case CALC_NSPIRE_CXIIT: case CALC_NSPIRE_CXIIT_CAS: return tixx_byte2type(NSP_CONST, NSP_MAXTYPES, data); + case CALC_NONE: + case CALC_TI80: case CALC_TIPRESENTER: + case CALC_MAX: default: tifiles_critical("%s: invalid model argument.", __FUNCTION__); return ""; @@ -199,7 +202,10 @@ uint8_t TICALL tifiles_string2vartype(CalcModel model, const char *s) case CALC_NSPIRE_CXIIT: case CALC_NSPIRE_CXIIT_CAS: return tixx_type2byte(NSP_CONST, NSP_MAXTYPES, s); + case CALC_NONE: + case CALC_TI80: case CALC_TIPRESENTER: + case CALC_MAX: default: tifiles_critical("%s: invalid model argument.", __FUNCTION__); return 0; @@ -282,7 +288,10 @@ const char *TICALL tifiles_vartype2fext(CalcModel model, uint8_t data) case CALC_NSPIRE_CXIIT: case CALC_NSPIRE_CXIIT_CAS: return tixx_byte2fext(NSP_CONST, NSP_MAXTYPES, data, "tn?"); + case CALC_NONE: + case CALC_TI80: case CALC_TIPRESENTER: + case CALC_MAX: default: tifiles_critical("%s: invalid model argument.", __FUNCTION__); return ""; @@ -371,7 +380,10 @@ uint8_t TICALL tifiles_fext2vartype(CalcModel model, const char *s) case CALC_NSPIRE_CXIIT: case CALC_NSPIRE_CXIIT_CAS: return tixx_fext2byte(NSP_CONST, NSP_MAXTYPES, s); + case CALC_NONE: + case CALC_TI80: case CALC_TIPRESENTER: + case CALC_MAX: default: tifiles_critical("%s: invalid model argument.", __FUNCTION__); return 0; @@ -455,7 +467,10 @@ const char *TICALL tifiles_vartype2type(CalcModel model, uint8_t vartype) case CALC_NSPIRE_CXIIT: case CALC_NSPIRE_CXIIT_CAS: return tixx_byte2desc(NSP_CONST, NSP_MAXTYPES, vartype); + case CALC_NONE: + case CALC_TI80: case CALC_TIPRESENTER: + case CALC_MAX: default: tifiles_critical("%s: invalid model argument.", __FUNCTION__); return ""; @@ -539,7 +554,10 @@ const char *TICALL tifiles_vartype2icon(CalcModel model, uint8_t vartype) case CALC_NSPIRE_CXIIT: case CALC_NSPIRE_CXIIT_CAS: return tixx_byte2icon(NSP_CONST, NSP_MAXTYPES, vartype); + case CALC_NONE: + case CALC_TI80: case CALC_TIPRESENTER: + case CALC_MAX: default: tifiles_critical("%s: invalid model argument.", __FUNCTION__); return ""; @@ -562,8 +580,6 @@ uint8_t TICALL tifiles_folder_type(CalcModel model) { switch (model) { - case CALC_NONE: - return -1; #ifndef DISABLE_TI8X case CALC_TI73: return TI73_DIR; @@ -621,7 +637,9 @@ uint8_t TICALL tifiles_folder_type(CalcModel model) case CALC_NSPIRE_CXIIT: case CALC_NSPIRE_CXIIT_CAS: return NSP_DIR; + case CALC_NONE: case CALC_TIPRESENTER: + case CALC_MAX: default: tifiles_critical("%s: invalid model argument.", __FUNCTION__); break; @@ -642,8 +660,6 @@ uint8_t TICALL tifiles_flash_type(CalcModel model) { switch (model) { - case CALC_NONE: - return -1; #ifndef DISABLE_TI8X case CALC_TI73: return TI73_APPL; @@ -701,8 +717,9 @@ uint8_t TICALL tifiles_flash_type(CalcModel model) case CALC_NSPIRE_CXII_CAS: case CALC_NSPIRE_CXIIT: case CALC_NSPIRE_CXIIT_CAS: + case CALC_NONE: case CALC_TIPRESENTER: - return -1; + case CALC_MAX: default: tifiles_critical("%s: invalid model argument.", __FUNCTION__); break; @@ -723,8 +740,6 @@ uint8_t TICALL tifiles_idlist_type(CalcModel model) { switch (model) { - case CALC_NONE: - return -1; #ifndef DISABLE_TI8X case CALC_TI73: return TI73_IDLIST; @@ -783,6 +798,8 @@ uint8_t TICALL tifiles_idlist_type(CalcModel model) case CALC_NSPIRE_CXIIT_CAS: case CALC_TIPRESENTER: return -1; + case CALC_NONE: + case CALC_MAX: default: tifiles_critical("%s: invalid model argument.", __FUNCTION__); break; @@ -866,6 +883,7 @@ const char *TICALL tifiles_calctype2signature(CalcModel model) case CALC_NSPIRE_CXIIT_CAS: case CALC_TIPRESENTER: return ""; + case CALC_MAX: default: tifiles_critical("%s: invalid model argument.", __FUNCTION__); break;