From 1ed8c3d59c473d6aa79f8baed53aee7fbce5e5db Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Sat, 5 Sep 2015 14:04:04 +0000 Subject: [PATCH] CMM: remove strncpy() function, replace it by strlcpy() as more stable git-svn-id: svn://kolibrios.org@5803 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/cmm/browser/WebView.c | 4 +-- programs/cmm/eolite/Eolite.c | 2 +- programs/cmm/eolite/include/left_panel.h | 4 +-- programs/cmm/lib/file_system.h | 8 +++--- programs/cmm/lib/strings.h | 34 +++--------------------- programs/cmm/pixie/pixie.c | 2 -- 6 files changed, 12 insertions(+), 42 deletions(-) diff --git a/programs/cmm/browser/WebView.c b/programs/cmm/browser/WebView.c index 431779d797..775fb3c030 100644 --- a/programs/cmm/browser/WebView.c +++ b/programs/cmm/browser/WebView.c @@ -292,7 +292,7 @@ void Scan(dword id__) } else { - strncpy(#URL,"http://",7); + strlcpy(#URL,"http://",7); strcat(#URL, #editURL); } OpenPage(); @@ -336,7 +336,7 @@ void Scan(dword id__) return; case DOWNLOAD_MANAGER: if (!downloader_opened) { - strncpy(#DL_URL, "http://",7); + strlcpy(#DL_URL, "http://",7); CreateThread(#Downloader,#downloader_stak+4092); } return; /* diff --git a/programs/cmm/eolite/Eolite.c b/programs/cmm/eolite/Eolite.c index da6a99af18..14cae823c5 100644 --- a/programs/cmm/eolite/Eolite.c +++ b/programs/cmm/eolite/Eolite.c @@ -397,7 +397,7 @@ void main() Paste(); break; case 032: //Ctrl+D - set as bg - strncpy(#temp, "\\S__",4); + strlcpy(#temp, "\\S__",4); strcat(#temp, #file_path); RunProgram("/sys/media/kiv", #temp); break; diff --git a/programs/cmm/eolite/include/left_panel.h b/programs/cmm/eolite/include/left_panel.h index 7f408d8ffe..56ef4463dc 100644 --- a/programs/cmm/eolite/include/left_panel.h +++ b/programs/cmm/eolite/include/left_panel.h @@ -94,7 +94,7 @@ void GetSystemDiscs() for (j1=0; j1=1073741824) strncpy(#size_nm, "Gb",2); - else if (bytes>=1048576) strncpy(#size_nm, "Mb",2); - else if (bytes>=1024) strncpy(#size_nm, "Kb",2); - else strncpy(#size_nm, "b ",2); + if (bytes>=1073741824) strlcpy(#size_nm, "Gb",2); + else if (bytes>=1048576) strlcpy(#size_nm, "Mb",2); + else if (bytes>=1024) strlcpy(#size_nm, "Kb",2); + else strlcpy(#size_nm, "b ",2); while (bytes>1023) bytes/=1024; sprintf(#ConvertSize_size_prefix,"%d %s",bytes,#size_nm); return #ConvertSize_size_prefix; diff --git a/programs/cmm/lib/strings.h b/programs/cmm/lib/strings.h index c3dd417d3f..4c00248261 100644 --- a/programs/cmm/lib/strings.h +++ b/programs/cmm/lib/strings.h @@ -13,7 +13,7 @@ // strlen( EDI) // utf8_strlen( ESI) // strcpy( EDI, ESI) --- 0 if == -// strncpy(dword text1,text2,signed length) +// strlcpy(dword text1,text2,signed length) // strcat( EDI, ESI) // strncat(dword text1,text2,signed length) --- pasting the text of a certain length // strchr( ESI,BL) --- find first BL @@ -216,34 +216,6 @@ L2: $jnz L2 } -inline dword strncpy(dword text1, text2, signed len) - signed o1,o2; -{ - if(!text1)||(!len) return text1; - if(len<4) - { - o2 = len; - goto RUN_BYTE; - } - o1 = len/4; - o2 = len-4*o1; - while(o1){ - DSDWORD[text1] = DSDWORD[text2]; - text1 += 4; - text2 += 4; - $dec o1 - } - RUN_BYTE: - while(o2){ - DSBYTE[text1] = DSBYTE[text2]; - $inc text1 - $inc text2 - $dec o2 - } - DSBYTE[text1] = 0; - return text1; -} - inline fastcall int strlcpy(dword ESI, EDI, EBX) { if (EBX<0) return -1; @@ -759,7 +731,7 @@ inline dword strdup(dword text) dword l = strlen(text); dword ret = malloc(l+1); if(!ret) return NULL; - strncpy(ret,text,l); + strlcpy(ret,text,l); return ret; } @@ -771,7 +743,7 @@ inline dword strndup(dword str, signed maxlen) copy = malloc(len + 1); if (copy != NULL) { - strncpy(copy, str, len); + strlcpy(copy, str, len); DSBYTE[len+copy] = '\0'; } return copy; diff --git a/programs/cmm/pixie/pixie.c b/programs/cmm/pixie/pixie.c index 60471ea54f..65c8110c2f 100644 --- a/programs/cmm/pixie/pixie.c +++ b/programs/cmm/pixie/pixie.c @@ -149,8 +149,6 @@ void main() mouse.get(); if (tmp_x!=mouse.x) || (tmp_y!=mouse.y) { - debugi(mouse.x); - debugi(tmp_x); z1 = Form.left + mouse.x - tmp_x; z2 = Form.top + mouse.y - tmp_y; if(z1<=10) || (z1>20000) z1=0; else if(z1>screen.width-Form.width-10)z1=screen.width-Form.width;