fixed some warnings

This commit is contained in:
Timerix22 2022-05-08 15:06:38 +03:00
parent c6c70c6fcc
commit c9864f3b68
13 changed files with 52 additions and 33 deletions

View File

@ -1,12 +1,24 @@
<component name="InspectionProjectProfileManager"> <component name="InspectionProjectProfileManager">
<profile version="1.0"> <profile version="1.0">
<option name="myName" value="Project Default" /> <option name="myName" value="Project Default" />
<inspection_tool class="ClangTidy" enabled="true" level="WARNING" enabled_by_default="true">
<option name="clangTidyCheckOptions">
<list>
<ClangTidyCheckOption />
</list>
</option>
<option name="clangTidyChecks" value="-*,bugprone-argument-comment,bugprone-assert-side-effect,bugprone-bad-signal-to-kill-thread,bugprone-branch-clone,bugprone-copy-constructor-init,bugprone-dangling-handle,bugprone-dynamic-static-initializers,bugprone-fold-init-type,bugprone-forward-declaration-namespace,bugprone-forwarding-reference-overload,bugprone-inaccurate-erase,bugprone-incorrect-roundings,bugprone-integer-division,bugprone-lambda-function-name,bugprone-macro-repeated-side-effects,bugprone-misplaced-operator-in-strlen-in-alloc,bugprone-misplaced-pointer-arithmetic-in-alloc,bugprone-misplaced-widening-cast,bugprone-move-forwarding-reference,bugprone-multiple-statement-macro,bugprone-no-escape,bugprone-not-null-terminated-result,bugprone-parent-virtual-call,bugprone-posix-return,bugprone-sizeof-container,bugprone-sizeof-expression,bugprone-spuriously-wake-up-functions,bugprone-string-constructor,bugprone-string-integer-assignment,bugprone-string-literal-with-embedded-nul,bugprone-suspicious-enum-usage,bugprone-suspicious-include,bugprone-suspicious-memory-comparison,bugprone-suspicious-memset-usage,bugprone-suspicious-missing-comma,bugprone-suspicious-semicolon,bugprone-suspicious-string-compare,bugprone-swapped-arguments,bugprone-terminating-continue,bugprone-throw-keyword-missing,bugprone-too-small-loop-variable,bugprone-undefined-memory-manipulation,bugprone-undelegated-constructor,bugprone-unhandled-self-assignment,bugprone-unused-raii,bugprone-unused-return-value,bugprone-use-after-move,bugprone-virtual-near-miss,cert-dcl21-cpp,cert-dcl58-cpp,cert-err34-c,cert-err52-cpp,cert-err58-cpp,cert-err60-cpp,cert-flp30-c,cert-msc50-cpp,cert-msc51-cpp,cert-str34-c,cppcoreguidelines-interfaces-global-init,cppcoreguidelines-narrowing-conversions,cppcoreguidelines-pro-type-member-init,cppcoreguidelines-pro-type-static-cast-downcast,cppcoreguidelines-slicing,google-default-arguments,google-explicit-constructor,google-runtime-operator,hicpp-exception-baseclass,hicpp-multiway-paths-covered,misc-misplaced-const,misc-new-delete-overloads,misc-no-recursion,misc-non-copyable-objects,misc-throw-by-value-catch-by-reference,misc-unconventional-assign-operator,misc-uniqueptr-reset-release,modernize-avoid-bind,modernize-concat-nested-namespaces,modernize-deprecated-headers,modernize-deprecated-ios-base-aliases,modernize-loop-convert,modernize-make-shared,modernize-make-unique,modernize-pass-by-value,modernize-raw-string-literal,modernize-redundant-void-arg,modernize-replace-auto-ptr,modernize-replace-disallow-copy-and-assign-macro,modernize-replace-random-shuffle,modernize-return-braced-init-list,modernize-shrink-to-fit,modernize-unary-static-assert,modernize-use-auto,modernize-use-bool-literals,modernize-use-emplace,modernize-use-equals-default,modernize-use-equals-delete,modernize-use-nodiscard,modernize-use-noexcept,modernize-use-nullptr,modernize-use-override,modernize-use-transparent-functors,modernize-use-uncaught-exceptions,mpi-buffer-deref,mpi-type-mismatch,openmp-use-default-none,performance-faster-string-find,performance-for-range-copy,performance-implicit-conversion-in-loop,performance-inefficient-algorithm,performance-inefficient-string-concatenation,performance-inefficient-vector-operation,performance-move-const-arg,performance-move-constructor-init,performance-no-automatic-move,performance-noexcept-move-constructor,performance-trivially-destructible,performance-type-promotion-in-math-fn,performance-unnecessary-copy-initialization,performance-unnecessary-value-param,portability-simd-intrinsics,readability-avoid-const-params-in-decls,readability-const-return-type,readability-container-size-empty,readability-convert-member-functions-to-static,readability-delete-null-pointer,readability-deleted-default,readability-inconsistent-declaration-parameter-name,readability-make-member-function-const,readability-misleading-indentation,readability-misplaced-array-index,readability-non-const-parameter,readability-redundant-control-flow,readability-redundant-declaration,readability-redundant-function-ptr-dereference,readability-redundant-smartptr-get,readability-redundant-string-cstr,readability-redundant-string-init,readability-simplify-subscript-expr,readability-static-accessed-through-instance,readability-static-definition-in-anonymous-namespace,readability-string-compare,readability-uniqueptr-delete-release,readability-use-anyofallof" />
</inspection_tool>
<inspection_tool class="EmptyDeclOrStmt" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="GrazieInspection" enabled="false" level="TYPO" enabled_by_default="false" /> <inspection_tool class="GrazieInspection" enabled="false" level="TYPO" enabled_by_default="false" />
<inspection_tool class="LanguageDetectionInspection" enabled="false" level="WARNING" enabled_by_default="false" /> <inspection_tool class="LanguageDetectionInspection" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="Misra" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="OCUnusedGlobalDeclaration" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false"> <inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
<option name="processCode" value="true" /> <option name="processCode" value="true" />
<option name="processLiterals" value="true" /> <option name="processLiterals" value="true" />
<option name="processComments" value="true" /> <option name="processComments" value="true" />
</inspection_tool> </inspection_tool>
<inspection_tool class="UnconstrainedVariableType" enabled="true" level="WARNING" enabled_by_default="true" />
</profile> </profile>
</component> </component>

View File

@ -7,7 +7,6 @@
</sourceRoots> </sourceRoots>
<excludeRoots> <excludeRoots>
<file path="$PROJECT_DIR$/.vscode" /> <file path="$PROJECT_DIR$/.vscode" />
<file path="$PROJECT_DIR$/bin" />
</excludeRoots> </excludeRoots>
</component> </component>
<component name="ExternalStorageConfigurationManager" enabled="true" /> <component name="ExternalStorageConfigurationManager" enabled="true" />

View File

@ -3,10 +3,10 @@ TESTS=$(wildcard tests/*c) $(wildcard tests/**/*.c)
OUTDIR=bin OUTDIR=bin
CMP=gcc CMP=gcc
OPT_ARGS=-O2 -std=c17 OPT_ARGS=-O2 -flto -std=c17
WARN_ARGS=-Wall -Wno-discarded-qualifiers WARN_ARGS=-Wall -Wno-discarded-qualifiers
all: clear_c clear_bin build_test build_lib all: clear_c clear_bin build_test_dbg
clear_c: clear_c:
clear clear
@ -43,6 +43,16 @@ build_lib:
@echo -e '\n\e[96m-------------[build_lib]--------------\e[0m' @echo -e '\n\e[96m-------------[build_lib]--------------\e[0m'
$(CMP) $(LIB_ARGS) -o $(OUTDIR)/$(LIB_FILE) $(CMP) $(LIB_ARGS) -o $(OUTDIR)/$(LIB_FILE)
DLL_ARGS=$(OPT_ARGS) $(WARN_ARGS)\
-shared -fpic -static-libgcc -static-libstdc++\
$(SRC) tests/test_marshalling.c
DLL_FILE=kerep.dll
build_dll:
gcc --version
@echo -e '\n\e[96m-------------[build_dll]--------------\e[0m'
$(CMP) $(DLL_ARGS) -o $(OUTDIR)/$(DLL_FILE)
###################################### ######################################
###### Run tasks ####### ###### Run tasks #######
###################################### ######################################

View File

@ -44,7 +44,7 @@ Maybe ERROR_WRONGCHAR(const char c, char* _text, char* text_first, const char* s
if(!_c) break; if(!_c) break;
} }
char errmsg[1024]; char errmsg[1024];
IFWIN( IFMSC(
sprintf_s(errmsg,1024, "unexpected <%c> at:\n" sprintf_s(errmsg,1024, "unexpected <%c> at:\n"
" \"%s\"\n" " \"%s\"\n"
"\\___[%s:%d] %s()", "\\___[%s:%d] %s()",
@ -85,7 +85,6 @@ Maybe __ReadName(DeserializeSharedData* shared){
case '[': case ']': case '[': case ']':
case '{': case '{':
safethrow_wrongchar(c,;); safethrow_wrongchar(c,;);
break;
case '#': ; case '#': ;
char _c=c; char _c=c;
char* _text=text; char* _text=text;
@ -180,7 +179,6 @@ Maybe __ParseValue(DeserializeSharedData* shared, string str){
else if(string_compare(str,falseStr)) else if(string_compare(str,falseStr))
return SUCCESS(UniFalse); return SUCCESS(UniFalse);
else safethrow_wrongchar(*str.ptr,;); else safethrow_wrongchar(*str.ptr,;);
break;
// Float64 // Float64
case 'f': { case 'f': {
char* _c=string_extract(str); char* _c=string_extract(str);
@ -192,9 +190,9 @@ Maybe __ParseValue(DeserializeSharedData* shared, string str){
case 'u': { case 'u': {
uint64 lu=0; uint64 lu=0;
char* _c=string_extract(str); char* _c=string_extract(str);
if(sscanf(_c,"%lu",&lu)!=1){ if(sscanf(_c, IFWIN("%llu", "%lu"), &lu)!=1){
char err[64]; char err[64];
IFWIN( IFMSC(
sprintf_s(err,64,"can't parse to int: <%s>",_c), sprintf_s(err,64,"can't parse to int: <%s>",_c),
sprintf(err,"can't parse to int: <%s>",_c) sprintf(err,"can't parse to int: <%s>",_c)
); );
@ -208,9 +206,9 @@ Maybe __ParseValue(DeserializeSharedData* shared, string str){
case '5': case '6': case '7': case '8': case '9': { case '5': case '6': case '7': case '8': case '9': {
int64 li=0; int64 li=0;
char* _c=string_extract(str); char* _c=string_extract(str);
if(sscanf(_c,"%li",&li)!=1){ if(sscanf(_c, IFWIN("%lli", "%li"), &li)!=1){
char err[64]; char err[64];
IFWIN( IFMSC(
sprintf_s(err,64,"can't parse to int: <%s>",_c), sprintf_s(err,64,"can't parse to int: <%s>",_c),
sprintf(err,"can't parse to int: <%s>",_c) sprintf(err,"can't parse to int: <%s>",_c)
); );
@ -245,7 +243,6 @@ Maybe __ReadValue(DeserializeSharedData* shared, bool* readingList){
case '}': case '$': case '}': case '$':
case '\'': case '\'':
safethrow_wrongchar(c,Unitype_free(value)); safethrow_wrongchar(c,Unitype_free(value));
break;
case '#':; case '#':;
char _c=c; char _c=c;
char* _text=text; char* _text=text;

View File

@ -49,7 +49,6 @@ Maybe __AppendValue(SerializeSharedData* shared, Unitype u){
break; break;
case Null: case Null:
safethrow("Null isn't supported in DtsodV24",;); safethrow("Null isn't supported in DtsodV24",;);
break;
case AutoarrUnitypePtr: case AutoarrUnitypePtr:
if(Autoarr_length(((Autoarr_Unitype*)(u.VoidPtr)))){ if(Autoarr_length(((Autoarr_Unitype*)(u.VoidPtr)))){
addc('\n'); addc('\n');

View File

@ -37,7 +37,7 @@ void Hashtable_expand(Hashtable* ht){
for(uint16 i=0;i<HT_HEIGHTS[ht->hein-1];i++){ for(uint16 i=0;i<HT_HEIGHTS[ht->hein-1];i++){
Autoarr(KVPair)* ar=ht->rows[i]; Autoarr(KVPair)* ar=ht->rows[i];
uint32 arlen=Autoarr_length(ar); uint32 arlen=Autoarr_length(ar);
for(uint16 k=0;k<arlen;k++){ for(uint32 k=0;k<arlen;k++){
KVPair p=Autoarr_get(ar,k); KVPair p=Autoarr_get(ar,k);
uint16 newrown=ihash(p.key)%HT_HEIGHTS[ht->hein]; uint16 newrown=ihash(p.key)%HT_HEIGHTS[ht->hein];
Autoarr(KVPair)* newar=newrows[newrown]; Autoarr(KVPair)* newar=newrows[newrown];

View File

@ -2,7 +2,6 @@
define_Autoarr(string) define_Autoarr(string)
#define MAXLENGTH 32768
#define BL_C 32 #define BL_C 32
#define BL_L 1024 #define BL_L 1024
@ -136,7 +135,7 @@ void StringBuilder_append_uint64(StringBuilder* b, uint64 a){
void StringBuilder_append_float64(StringBuilder* b, double a){ void StringBuilder_append_float64(StringBuilder* b, double a){
try_complete_buf(b); try_complete_buf(b);
char buf[32]; char buf[32];
IFWIN( IFMSC(
sprintf_s(buf,32,"%lf",a), sprintf_s(buf,32,"%lf",a),
sprintf(buf,"%lf",a) sprintf(buf,"%lf",a)
); );

View File

@ -20,7 +20,7 @@ char* errname(err_t err){
char* __genErrMsg(const char* errmsg, const char* srcfile, int line, const char* funcname){ char* __genErrMsg(const char* errmsg, const char* srcfile, int line, const char* funcname){
size_t bufsize=ERRMSG_MAXLENGTH; size_t bufsize=ERRMSG_MAXLENGTH;
char* rezult=malloc(bufsize); char* rezult=malloc(bufsize);
IFWIN( IFMSC(
sprintf_s(rezult,bufsize,"[%s:%d] %s() throwed error: %s",srcfile,line,funcname,errmsg), sprintf_s(rezult,bufsize,"[%s:%d] %s() throwed error: %s",srcfile,line,funcname,errmsg),
sprintf(rezult,"[%s:%d] %s() throwed error: %s",srcfile,line,funcname,errmsg) sprintf(rezult,"[%s:%d] %s() throwed error: %s",srcfile,line,funcname,errmsg)
); );
@ -30,7 +30,7 @@ char* __genErrMsg(const char* errmsg, const char* srcfile, int line, const char*
char* __extendErrMsg(const char* errmsg, const char* srcfile, int line, const char* funcname){ char* __extendErrMsg(const char* errmsg, const char* srcfile, int line, const char* funcname){
size_t bufsize=cptr_length(errmsg)+ERRMSG_MAXLENGTH; size_t bufsize=cptr_length(errmsg)+ERRMSG_MAXLENGTH;
char* rezult=malloc(bufsize); char* rezult=malloc(bufsize);
IFWIN( IFMSC(
sprintf_s(rezult,bufsize,"%s\n \\___[%s:%d] %s()",errmsg,srcfile,line,funcname), sprintf_s(rezult,bufsize,"%s\n \\___[%s:%d] %s()",errmsg,srcfile,line,funcname),
sprintf(rezult,"%s\n \\___[%s:%d] %s()",errmsg,srcfile,line,funcname) sprintf(rezult,"%s\n \\___[%s:%d] %s()",errmsg,srcfile,line,funcname)
); );

View File

@ -40,8 +40,13 @@ extern "C" {
#ifdef _MSC_VER #ifdef _MSC_VER
#define IFWIN(YES, NO) YES #define IFWIN(YES, NO) YES
#define IFMSC(YES, NO) NO
#elif defined(_WIN64) || defined(_WIN32)
#define IFWIN(YES, NO) YES
#define IFMSC(YES, NO) NO
#elif defined(__GNUC__) #elif defined(__GNUC__)
#define IFWIN(YES, NO) NO #define IFWIN(YES, NO) NO
#define IFMSC(YES, NO) NO
#else #else
#pragma GCC error "unknown compiler" #pragma GCC error "unknown compiler"
#endif #endif

View File

@ -116,7 +116,7 @@ void Unitype_free(Unitype u){
#define BUFSIZE 64 #define BUFSIZE 64
char* sprintuni(Unitype v){ char* sprintuni(Unitype v){
char* buf=malloc(BUFSIZE); char* buf=malloc(BUFSIZE);
IFWIN( IFMSC(
switch (v.type) { switch (v.type) {
case Null: sprintf_s(buf, BUFSIZE, "{Null}");break; case Null: sprintf_s(buf, BUFSIZE, "{Null}");break;
case Float64: sprintf_s(buf, BUFSIZE, "{%s : %lf}", my_type_name(v.type),v.Float64);break; case Float64: sprintf_s(buf, BUFSIZE, "{%s : %lf}", my_type_name(v.type),v.Float64);break;
@ -134,8 +134,8 @@ char* sprintuni(Unitype v){
case Null: sprintf(buf, "{Null}"); break; case Null: sprintf(buf, "{Null}"); break;
case Float64: sprintf(buf, "{%s : %lf}", my_type_name(v.type),v.Float64); break; case Float64: sprintf(buf, "{%s : %lf}", my_type_name(v.type),v.Float64); break;
case Bool: case Bool:
case UInt64: sprintf(buf, "{%s : %lu}", my_type_name(v.type),v.UInt64);break; case UInt64: sprintf(buf, "{%s : " IFWIN("%llu", "%lu") "}", my_type_name(v.type),v.UInt64); break;
case Int64: sprintf(buf, "{%s : %ld}", my_type_name(v.type),v.Int64);break; case Int64: sprintf(buf, "{%s : " IFWIN("%lld", "%ld") "}", my_type_name(v.type),v.Int64); break;
case CharPtr: ; case CharPtr: ;
size_t newBUFSIZE=cptr_length(v.VoidPtr) + BUFSIZE/2; size_t newBUFSIZE=cptr_length(v.VoidPtr) + BUFSIZE/2;
buf=realloc(buf, newBUFSIZE); buf=realloc(buf, newBUFSIZE);

View File

@ -20,17 +20,17 @@ static void printautoarr(Autoarr(uint16)* ar){
} }
static void fillar(Autoarr(uint16)* ar){ static void fillar(Autoarr(uint16)* ar){
for (uint16 i=0;i<Autoarr_max_length(ar);i++) for (uint32 i=0;i<Autoarr_max_length(ar);i++)
Autoarr_add(ar,i); Autoarr_add(ar,i);
} }
static void resetar(Autoarr(uint16)* ar){ static void resetar(Autoarr(uint16)* ar){
for (uint16 i=0;i<Autoarr_max_length(ar);i++) for (uint32 i=0;i<Autoarr_max_length(ar);i++)
Autoarr_set(ar,i,Autoarr_max_length(ar)-i-1); Autoarr_set(ar,i,Autoarr_max_length(ar)-i-1);
} }
static void printallval(Autoarr(uint16)* ar){ static void printallval(Autoarr(uint16)* ar){
printf("\e[90m"); printf("\e[90m");
for (uint16 i=0;i<Autoarr_length(ar);i++) for (uint32 i=0;i<Autoarr_length(ar);i++)
printf("%u ",Autoarr_get(ar,i)); printf("%u ",Autoarr_get(ar,i));
printf("\n"); printf("\n");
} }

View File

@ -38,7 +38,7 @@ void printrowgraph(Hashtable* ht){
char* genkey(uint32 i){ char* genkey(uint32 i){
char* key=malloc(12); char* key=malloc(12);
IFWIN( IFMSC(
sprintf_s(key,12,"key_%u",i), sprintf_s(key,12,"key_%u",i),
sprintf(key,"key_%u",i) sprintf(key,"key_%u",i)
); );

View File

@ -2,8 +2,6 @@
#include "../src/base/base.h" #include "../src/base/base.h"
void printuni(Unitype v);
void test_searchtree(); void test_searchtree();
void test_autoarr(); void test_autoarr();
void test_hashtable(); void test_hashtable();