Skip to content

Commit

Permalink
#92 (strcat -> strncat)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Jan 29, 2021
1 parent 929cd0c commit c2536b2
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 48 deletions.
14 changes: 11 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ set(header_eez_libs_image
list (APPEND header_files ${src_eez_libs_image})
source_group("eez\\libs\\image" FILES ${src_eez_libs_image} ${header_eez_libs_image})
if(MSVC)
set_source_files_properties(src/eez/libs/image/toojpeg.cpp PROPERTIES COMPILE_FLAGS /W0)
set_source_files_properties(src/eez/libs/image/toojpeg.cpp PROPERTIES COMPILE_FLAGS /W0)
endif()

set(src_eez_libs_mqtt
Expand Down Expand Up @@ -588,7 +588,7 @@ set(header_third_party_scpi
list (APPEND header_files ${header_third_party_scpi})
source_group("third_party\\scpi" FILES ${src_third_party_scpi} ${header_third_party_scpi})
if(MSVC)
set_source_files_properties(${src_third_party_scpi} PROPERTIES COMPILE_FLAGS /W0)
set_source_files_properties(${src_third_party_scpi} PROPERTIES COMPILE_FLAGS /W0)
endif()

set(src_third_party_micropython_extmod
Expand All @@ -608,6 +608,9 @@ set(src_third_party_micropython_ports_bb3
src/third_party/micropython/ports/bb3/gccollect.cpp
src/third_party/micropython/ports/bb3/mphalport.cpp
)
if (UNIX)
set_source_files_properties(${src_third_party_micropython_ports_bb3} PROPERTIES COMPILE_FLAGS -fpermissive)
endif()
list (APPEND src_files ${src_third_party_micropython_ports_bb3})
set(header_third_party_micropython_ports_bb3
src/third_party/micropython/ports/bb3/mpconfigport.h
Expand Down Expand Up @@ -757,6 +760,11 @@ set(src_third_party_micropython_py
src/third_party/micropython/py/vstr.c
src/third_party/micropython/py/warning.c
)
if (UNIX)
set_source_files_properties(${src_third_party_micropython_py} PROPERTIES COMPILE_FLAGS -fpermissive)
set_source_files_properties(${src_third_party_micropython_py} PROPERTIES COMPILE_FLAGS -Wpointer-to-int-cast)
set_source_files_properties(${src_third_party_micropython_py} PROPERTIES COMPILE_FLAGS -Wint-to-pointer-cast)
endif()
list (APPEND src_files ${src_third_party_micropython_py})
set(header_third_party_micropython_py
src/third_party/micropython/py/asmarm.h
Expand Down Expand Up @@ -821,7 +829,7 @@ set(header_third_party_micropython_py
list (APPEND header_files ${header_third_party_micropython_py})
source_group("third_party\\micropython\\py" FILES ${src_third_party_micropython_py} ${header_third_party_micropython_py})
if(MSVC)
set_source_files_properties(${src_third_party_micropython_py} PROPERTIES COMPILE_FLAGS /W0)
set_source_files_properties(${src_third_party_micropython_py} PROPERTIES COMPILE_FLAGS /W0)
endif()

if(WIN32)
Expand Down
22 changes: 11 additions & 11 deletions src/eez/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,35 +308,35 @@ void data_usb_keyboard_state(DataOperationEnum operation, Cursor cursor, Value &
}

if (g_keyboardInfo.lctrl) {
strcat(str, " LCTRL");
strncat(str, " LCTRL", KEYBOARD_INFO_STRING_SIZE - strlen(str) - 1);
}

if (g_keyboardInfo.lshift) {
strcat(str, " LSHIFT");
strncat(str, " LSHIFT", KEYBOARD_INFO_STRING_SIZE - strlen(str) - 1);
}

if (g_keyboardInfo.lalt) {
strcat(str, " LALT");
strncat(str, " LALT", KEYBOARD_INFO_STRING_SIZE - strlen(str) - 1);
}

if (g_keyboardInfo.lgui) {
strcat(str, " LGUI");
strncat(str, " LGUI", KEYBOARD_INFO_STRING_SIZE - strlen(str) - 1);
}

if (g_keyboardInfo.rctrl) {
strcat(str, " RCTRL");
strncat(str, " RCTRL", KEYBOARD_INFO_STRING_SIZE - strlen(str) - 1);
}

if (g_keyboardInfo.rshift) {
strcat(str, " RSHIFT");
strncat(str, " RSHIFT", KEYBOARD_INFO_STRING_SIZE - strlen(str) - 1);
}

if (g_keyboardInfo.ralt) {
strcat(str, " RALT");
strncat(str, " RALT", KEYBOARD_INFO_STRING_SIZE - strlen(str) - 1);
}

if (g_keyboardInfo.rgui) {
strcat(str, " RGUI");
strncat(str, " RGUI", KEYBOARD_INFO_STRING_SIZE - strlen(str) - 1);
}

for (int i = 0; i < 6; i++) {
Expand All @@ -357,15 +357,15 @@ void data_usb_keyboard_state(DataOperationEnum operation, Cursor cursor, Value &
}

if (g_mouseInfo.button1) {
strcat(str, " BTN1");
strncat(str, " BTN1", KEYBOARD_INFO_STRING_SIZE - strlen(str) - 1);
}

if (g_mouseInfo.button2) {
strcat(str, " BTN2");
strncat(str, " BTN2", KEYBOARD_INFO_STRING_SIZE - strlen(str) - 1);
}

if (g_mouseInfo.button3) {
strcat(str, " BTN3");
strncat(str, " BTN3", KEYBOARD_INFO_STRING_SIZE - strlen(str) - 1);
}
}

Expand Down
23 changes: 7 additions & 16 deletions src/eez/modules/psu/event_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,25 +395,16 @@ static void addEventToWriteQueue(int16_t eventId, char *message, int channelInde
}

static void getIndexFilePath(int indexType, char *filePath) {
strcpy(filePath, LOGS_DIR);

strcat(filePath, PATH_SEPARATOR);

if (indexType == EVENT_TYPE_DEBUG) {
strcat(filePath, LOG_DEBUG_INDEX_FILE_NAME);
} else if (indexType == EVENT_TYPE_INFO) {
strcat(filePath, LOG_INFO_INDEX_FILE_NAME);
} else if (indexType == EVENT_TYPE_WARNING) {
strcat(filePath, LOG_WARNING_INDEX_FILE_NAME);
} else {
strcat(filePath, LOG_ERROR_INDEX_FILE_NAME);
}
snprintf(filePath, MAX_PATH_LENGTH, "%s%s%s", LOGS_DIR, PATH_SEPARATOR,
indexType == EVENT_TYPE_DEBUG ? LOG_DEBUG_INDEX_FILE_NAME :
indexType == EVENT_TYPE_INFO ? LOG_INFO_INDEX_FILE_NAME :
indexType == EVENT_TYPE_WARNING ? LOG_WARNING_INDEX_FILE_NAME :
LOG_ERROR_INDEX_FILE_NAME
);
}

static void getLogFilePath(char *filePath) {
strcpy(filePath, LOGS_DIR);
strcat(filePath, PATH_SEPARATOR);
strcat(filePath, LOG_FILE_NAME);
snprintf(filePath, MAX_PATH_LENGTH, "%s%s%s", LOGS_DIR, PATH_SEPARATOR, LOG_FILE_NAME);
}

static int getFilter() {
Expand Down
4 changes: 2 additions & 2 deletions src/eez/mp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ void oneIter() {
void startScript(const char *filePath) {
if (g_state == STATE_IDLE) {
g_state = STATE_EXECUTING;
strncpy(g_scriptPath, filePath, sizeof(g_scriptPath));
g_scriptPath[sizeof(g_scriptPath) - 1] = 0;
strncpy(g_scriptPath, filePath, MAX_PATH_LENGTH);
g_scriptPath[MAX_PATH_LENGTH - 1] = 0;

//DebugTrace("T1 %d\n", millis());
sendMessageToLowPriorityThread(MP_LOAD_SCRIPT);
Expand Down
29 changes: 13 additions & 16 deletions src/eez/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,40 +114,37 @@ void strcatFloat(char *str, size_t maxStrLength, float value, int numDecimalPlac
}

void strcatVoltage(char *str, size_t maxStrLength, float value) {
strcatFloat(str, maxStrLength, value);
strcat(str, "V");
auto n = strlen(str);
snprintf(str + n, maxStrLength - n, "%g V", value);
}

void strcatCurrent(char *str, size_t maxStrLength, float value) {
strcatFloat(str, maxStrLength, value);
strcat(str, "A");
auto n = strlen(str);
snprintf(str + n, maxStrLength - n, "%g A", value);
}

void strcatPower(char *str, size_t maxStrLength, float value) {
strcatFloat(str, maxStrLength, value);
strcat(str, "W");
auto n = strlen(str);
snprintf(str + n, maxStrLength - n, "%g W", value);
}

void strcatDuration(char *str, size_t maxStrLength, float value) {
auto n = strlen(str);
if (value > 0.1) {
strcatFloat(str, maxStrLength, value);
strcat(str, " s");
snprintf(str + n, maxStrLength - n, "%g s", value);
} else {
strcatFloat(str, maxStrLength, value * 1000);
strcat(str, " ms");
snprintf(str + n, maxStrLength - n, "%g ms", value * 1000);
}
}

void strcatLoad(char *str, size_t maxStrLength, float value) {
auto n = strlen(str);
if (value < 1000) {
strcatFloat(str, maxStrLength, value);
strcat(str, " ohm");
snprintf(str + n, maxStrLength - n, "%g ohm", value);
} else if (value < 1000000) {
strcatFloat(str, maxStrLength, value / 1000);
strcat(str, " Kohm");
snprintf(str + n, maxStrLength - n, "%g Kohm", value / 1000);
} else {
strcatFloat(str, maxStrLength, value / 1000000);
strcat(str, " Mohm");
snprintf(str + n, maxStrLength - n, "%g Mohm", value / 1000000);
}
}

Expand Down

0 comments on commit c2536b2

Please sign in to comment.