C: fix minor compiler warnings

This commit is contained in:
Alexey Andreev 2019-07-09 11:40:39 +03:00
parent 4fa3db38a0
commit f4f80a88ea
3 changed files with 17 additions and 13 deletions

View File

@ -211,15 +211,19 @@ int64_t teavm_currentTimeNano() {
#endif
#ifdef _MSC_VER
#define gmtime_r(a, b) gmtime_s(a, b)
#define localtime_r(a, b) localtime_s(a, b)
#undef gmtime_r
#undef localtime_r
#define gmtime_r(a, b) gmtime_s(b, a)
#define localtime_r(a, b) localtime_s(b, a)
#endif
int32_t teavm_timeZoneOffset() {
struct tm tm;
time_t t = time(NULL);
time_t local = mktime(localtime_r(&t, &tm));
time_t utc = mktime(gmtime_r(&t, &tm));
localtime_r(&t, &tm);
time_t local = mktime(&tm);
gmtime_r(&t, &tm);
time_t utc = mktime(&tm);
return (int32_t) (difftime(utc, local) / 60);
}
@ -361,15 +365,14 @@ char* teavm_stringToC(void* obj) {
size_t sz = teavm_mbSize(javaChars, charArray->size);
char* result = malloc(sz + 1);
int32_t j = 0;
char* dst = result;
mbstate_t state = {0};
for (int32_t i = 0; i < charArray->size; ++i) {
size_t result = c16rtomb(dst, javaChars[i], &state);
if (result == (size_t) -1) {
size_t charResult = c16rtomb(dst, javaChars[i], &state);
if (charResult == (size_t) -1) {
break;
}
dst += result;
dst += charResult;
}
*dst = '\0';
return result;
@ -449,7 +452,6 @@ char* teavm_char16ToMb(char16_t* javaChars, int32_t length) {
size_t sz = teavm_mbSize(javaChars, length);
char* cchars = malloc(sz + 1);
int32_t j = 0;
char* dst = cchars;
mbstate_t state = {0};
for (int32_t i = 0; i < length; ++i) {
@ -548,7 +550,7 @@ TeaVM_StringList* teavm_appendString(TeaVM_StringList* list, char16_t* data, int
}
#ifndef TEAVM_WINDOWS_LOG
void teavm_logchar(char16_t c) {
void teavm_logchar(int32_t c) {
putwchar(c);
}
#else

View File

@ -178,7 +178,7 @@ static inline float teavm_getNaN() {
typedef struct {
int32_t size;
void* data[0];
void* data[1];
} TeaVM_ResourceArray;
typedef struct {
@ -188,7 +188,7 @@ typedef struct {
typedef struct {
int32_t size;
TeaVM_ResourceMapEntry entries[0];
TeaVM_ResourceMapEntry entries[1];
} TeaVM_ResourceMap;
extern int32_t teavm_hashCode(TeaVM_String*);
@ -332,6 +332,7 @@ extern TeaVM_StringList* teavm_appendString(TeaVM_StringList*, char16_t*, int32_
extern int32_t teavm_file_homeDirectory(char16_t**);
extern int32_t teavm_file_workDirectory(char16_t**);
extern int32_t teavm_file_tempDirectory(char16_t**);
extern int32_t teavm_file_isFile(char16_t*, int32_t);
extern int32_t teavm_file_isDir(char16_t*, int32_t);
extern int32_t teavm_file_canRead(char16_t*, int32_t);
@ -352,6 +353,7 @@ extern int32_t teavm_file_tell(int64_t);
extern int32_t teavm_file_read(int64_t, int8_t*, int32_t, int32_t);
extern int32_t teavm_file_write(int64_t, int8_t*, int32_t, int32_t);
extern int32_t teavm_file_isWindows();
extern int32_t teavm_file_canonicalize(char16_t*, int32_t, char16_t**);
#ifdef _MSC_VER
extern int64_t teavm_unixTimeOffset;

View File

@ -100,7 +100,7 @@ TeaVM_String* teavm_registerString(TeaVM_String* str) {
if (teavm_stringHashtable[index] == NULL) {
if (teavm_stringHashtableFill >= teavm_stringHashtableThreshold) {
teavm_rehashStrings();
int32_t index = (uint32_t) hash % teavm_stringHashtableSize;
index = (uint32_t) hash % teavm_stringHashtableSize;
}
teavm_stringHashtableFill++;
}