diff --git a/include/os/os.h b/include/os/os.h index ac1a750b78..1749687d97 100644 --- a/include/os/os.h +++ b/include/os/os.h @@ -97,6 +97,7 @@ extern "C" { #include #endif + #include "osThread.h" #include "osAtomic.h" diff --git a/include/os/osTime.h b/include/os/osTime.h index 87df3a2650..c367416175 100644 --- a/include/os/osTime.h +++ b/include/os/osTime.h @@ -65,28 +65,28 @@ int32_t taosGetTimestampSec(); //@return timestamp in millisecond static FORCE_INLINE int64_t taosGetTimestampMs() { struct timeval systemTime; - taosGetTimeOfDay(&systemTime); + (void)taosGetTimeOfDay(&systemTime); return (int64_t)systemTime.tv_sec * 1000LL + (int64_t)systemTime.tv_usec / 1000; } //@return timestamp in microsecond static FORCE_INLINE int64_t taosGetTimestampUs() { struct timeval systemTime; - taosGetTimeOfDay(&systemTime); + (void)taosGetTimeOfDay(&systemTime); return (int64_t)systemTime.tv_sec * 1000000LL + (int64_t)systemTime.tv_usec; } //@return timestamp in nanosecond static FORCE_INLINE int64_t taosGetTimestampNs() { struct timespec systemTime = {0}; - taosClockGetTime(CLOCK_REALTIME, &systemTime); + (void)taosClockGetTime(CLOCK_REALTIME, &systemTime); return (int64_t)systemTime.tv_sec * 1000000000LL + (int64_t)systemTime.tv_nsec; } //@return timestamp of monotonic clock in millisecond static FORCE_INLINE int64_t taosGetMonoTimestampMs() { struct timespec systemTime = {0}; - taosClockGetTime(CLOCK_MONOTONIC, &systemTime); + (void)taosClockGetTime(CLOCK_MONOTONIC, &systemTime); return (int64_t)systemTime.tv_sec * 1000LL + (int64_t)systemTime.tv_nsec / 1000000; } diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index 667c3c146a..4348629467 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -44,7 +44,7 @@ int wordexp(char *words, wordexp_t *pwordexp, int flags) { pwordexp->we_wordc = 1; pwordexp->we_wordv[0] = pwordexp->wordPos; - memset(pwordexp->wordPos, 0, 1025); + (void)memset(pwordexp->wordPos, 0, 1025); if (_fullpath(pwordexp->wordPos, words, 1024) == NULL) { pwordexp->we_wordv[0] = words; printf("failed to parse relative path:%s to abs path\n", words); @@ -100,7 +100,7 @@ void taosRemoveDir(const char *dirname) { if (strcmp(taosGetDirEntryName(de), ".") == 0 || strcmp(taosGetDirEntryName(de), "..") == 0) continue; char filename[1024] = {0}; - snprintf(filename, sizeof(filename), "%s%s%s", dirname, TD_DIRSEP, taosGetDirEntryName(de)); + (void)snprintf(filename, sizeof(filename), "%s%s%s", dirname, TD_DIRSEP, taosGetDirEntryName(de)); if (taosDirEntryIsDir(de)) { taosRemoveDir(filename); } else { @@ -110,7 +110,7 @@ void taosRemoveDir(const char *dirname) { } taosCloseDir(&pDir); - rmdir(dirname); + (void)rmdir(dirname); // printf("dir:%s is removed\n", dirname); return; diff --git a/source/os/src/osMemory.c b/source/os/src/osMemory.c index d130ebe469..3e49808dad 100644 --- a/source/os/src/osMemory.c +++ b/source/os/src/osMemory.c @@ -186,7 +186,7 @@ static void print_line(Dwarf_Debug dbg, Dwarf_Line line, Dwarf_Addr pc) { dwarf_linesrc(line, &linesrc, NULL); dwarf_lineno(line, &lineno, NULL); } - printf("BackTrace %08" PRId64 " %s:%" DW_PR_DUu "\n", taosGetSelfPthreadId(), linesrc, lineno); + (void)printf("BackTrace %08" PRId64 " %s:%" DW_PR_DUu "\n", taosGetSelfPthreadId(), linesrc, lineno); if (line) dwarf_dealloc(dbg, linesrc, DW_DLA_STRING); } void taosPrintBackTrace() { @@ -266,7 +266,11 @@ void *taosMemoryMalloc(int64_t size) { return (char *)tmp + sizeof(TdMemoryInfo); #else - return malloc(size); + void* p = malloc(size); + if (NULL == p) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + } + return p; #endif } @@ -283,7 +287,11 @@ void *taosMemoryCalloc(int64_t num, int64_t size) { return (char *)tmp + sizeof(TdMemoryInfo); #else - return calloc(num, size); + void* p = calloc(num, size); + if (NULL == p) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + } + return p; #endif } @@ -309,7 +317,11 @@ void *taosMemoryRealloc(void *ptr, int64_t size) { return (char *)tmp + sizeof(TdMemoryInfo); #else - return realloc(ptr, size); + void* p = realloc(ptr, size); + if (size > 0 && NULL == p) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + } + return p; #endif } @@ -330,7 +342,12 @@ char *taosStrdup(const char *ptr) { return (char *)tmp + sizeof(TdMemoryInfo); #else - return tstrdup(ptr); + char* p = tstrdup(ptr); + if (ptr != NULL && NULL == p) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + } + return p; + #endif } @@ -357,8 +374,7 @@ int64_t taosMemorySize(void *ptr) { TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char *)ptr - sizeof(TdMemoryInfo)); ASSERT(pTdMemoryInfo->symbol == TD_MEMORY_SYMBOL); if (pTdMemoryInfo->symbol != TD_MEMORY_SYMBOL) { - +return NULL; - + + return NULL; } return pTdMemoryInfo->memorySize; @@ -378,7 +394,7 @@ void taosMemoryTrim(int32_t size) { // do nothing return; #else - malloc_trim(size); + (void)malloc_trim(size); #endif } @@ -388,6 +404,13 @@ void *taosMemoryMallocAlign(uint32_t alignment, int64_t size) { #else #if defined(LINUX) void *p = memalign(alignment, size); + if (NULL == p) { + if (ENOMEM == errno) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + } else { + terrno = TAOS_SYSTEM_ERROR(errno); + } + } return p; #else return taosMemoryMalloc(size); diff --git a/source/os/src/osRand.c b/source/os/src/osRand.c index 0e58b7a8ec..da4e8dfb9d 100644 --- a/source/os/src/osRand.c +++ b/source/os/src/osRand.c @@ -69,7 +69,7 @@ uint32_t taosSafeRand(void) { if (len < 0) { seed = (int)taosGetTimestampSec(); } - taosCloseFile(&pFile); + (void)taosCloseFile(&pFile); } return (uint32_t)seed; diff --git a/source/os/src/osTime.c b/source/os/src/osTime.c index 9cad1dd6ef..c650ac989d 100644 --- a/source/os/src/osTime.c +++ b/source/os/src/osTime.c @@ -345,6 +345,7 @@ char *taosStrpTime(const char *buf, const char *fmt, struct tm *tm) { } int32_t taosGetTimeOfDay(struct timeval *tv) { + int32_t code = 0; #ifdef WINDOWS LARGE_INTEGER t; FILETIME f; @@ -359,11 +360,18 @@ int32_t taosGetTimeOfDay(struct timeval *tv) { tv->tv_usec = (t.QuadPart % 10000000) / 10; return 0; #else - return gettimeofday(tv, NULL); + code = gettimeofday(tv, NULL); + return (-1 == code) ? (terrno = TAOS_SYSTEM_ERROR(errno)) : 0; #endif } -time_t taosTime(time_t *t) { return time(t); } +time_t taosTime(time_t *t) { + time_t r = time(t); + if (r == (time_t)-1) { + terrno = TAOS_SYSTEM_ERROR(errno); + } + return r; +} /* * mktime64 - Converts date to seconds. @@ -458,7 +466,11 @@ time_t taosMktime(struct tm *timep) { timep->tm_sec, tz); #endif #else - return mktime(timep); + time_t r = mktime(timep); + if (r == (time_t)-1) { + terrno = TAOS_SYSTEM_ERROR(errno); + } + return r; #endif } @@ -470,7 +482,7 @@ struct tm *taosLocalTime(const time_t *timep, struct tm *result, char *buf) { if (result == NULL) { res = localtime(timep); if (res == NULL && buf != NULL) { - sprintf(buf, "NaN"); + (void)sprintf(buf, "NaN"); } return res; } @@ -528,7 +540,7 @@ struct tm *taosLocalTime(const time_t *timep, struct tm *result, char *buf) { #else res = localtime_r(timep, result); if (res == NULL && buf != NULL) { - sprintf(buf, "NaN"); + (void)sprintf(buf, "NaN"); } #endif return result; @@ -642,6 +654,7 @@ struct tm *taosLocalTimeNolock(struct tm *result, const time_t *timep, int dst) int32_t taosGetTimestampSec() { return (int32_t)time(NULL); } int32_t taosClockGetTime(int clock_id, struct timespec *pTS) { + int32_t code = 0; #ifdef WINDOWS LARGE_INTEGER t; FILETIME f; @@ -656,6 +669,7 @@ int32_t taosClockGetTime(int clock_id, struct timespec *pTS) { pTS->tv_nsec = (t.QuadPart % 10000000) * 100; return (0); #else - return clock_gettime(clock_id, pTS); + code = clock_gettime(clock_id, pTS); + return (-1 == code) ? (terrno = TAOS_SYSTEM_ERROR(errno)) : 0; #endif }