mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-03 18:14:25 +03:00
e48cb7c89f
valgrind detected an error in completion path: ==2962== Source and destination overlap in strcpy(0x459F068, 0x459F06A) ==2962== at 0x4026056: strcpy (mc_replace_strmem.c:268) ==2962== by 0x808F70B: canonicalize_pathname (string3.h:106) ==2962== by 0x805ECBA: filename_completion_function (complete.c:125) ==2962== by 0x805FB35: command_completion_function (complete.c:448) ==2962== by 0x805EA34: completion_matches (complete.c:552) ==2962== by 0x8060454: complete (complete.c:735) ==2962== by 0x809AAC4: handle_char (widget.c:1545) ==2962== by 0x807867E: midnight_callback (dialog.h:201) ==2962== by 0x8061B27: dlg_process_event (dialog.c:664) ==2962== by 0x8061ECE: run_dlg (dialog.c:786) ==2962== by 0x807996C: main (main.c:1674) Snippet of man strcpy: DESCRIPTION The strcpy() function copies the string pointed to by src, including the terminating null byte ('\0'), to the buffer pointed to by dest. ___The strings may not overlap___, and the destination string dest must be large enough to receive the copy. We used strcpy to move data chunk in memory: "./foo" -> "foo", etc. This patch introduces mhl_strmove and fixed canonicalize_pathname. Signed-off-by: Sergei Trofimovich <st@anti-virus.by> |
||
---|---|---|
.. | ||
.gitignore | ||
env.h | ||
escape.h | ||
memory.h | ||
README | ||
strhash.h | ||
string.h | ||
types.h |
Micro helper library. -- This is a tiny library of helper functions/macros. * MACRO-FUNC: macro w/ function syntax. (might become inline func) * INLINE-FUNC: inline function (might become macro func) * MACRO: strictly a macro (may never become a inline func) -- mhl/memory.h: Memory management functions * mhl_mem_alloc_u(sz) [MACRO-FUNC] Allocate sz bytes on stack, unitialized * mhl_mem_alloc_z(sz) [INLINE-FUNC] Allocate sz bytes on stack, zero'ed * mhl_mem_free(ptr) [INLINE-FUNC] Free chunk @ptr (MUST be allocated w/ mhl_mem_alloc_*()), passing NULL is graciously allowed * mhl_mem_realloc(ptr,newsize) -> returns newptr Re-allocates a heap chunk, just like realloc() * MHL_PTR_FREE(ptr) [MACRO-ONLY] like mhl_mem_free(), but with ptr as a variable that gets cleared (use this as shortcut to "mhl_mem_free(foo); foo = NULL") mhl/string.h: String helpers * mhl_str_dup(const char*s) -> char* [MACRO-FUNC] Safe version of strdup(), when NULL passed, returns strdup("") * mhl_str_ndup(const char* s) -> char* [MACRO-FUNC] Safe version of strndup(), when NULL passed, returns strdup("") * mhl_str_trim(char* s) -> char* [INLINE-FUNC] Trims the string (removing leading and trailing whitespacs), WITHIN the passed buffer, returning the string s itself. When NULL passed returns NULL. * mhl_str_toupper(char* s) -> char* [INLINE-FUNC] Converts the string in passed buffer to uppercase, returns that buffer. When NULL passed returns NULL. * mhl_str_concat_1(const char* base, const char* one) -> char* [INLINE-FUNC] Concatenates the string one onto the string base and returns the result in a newly allocated buffer (free it w/ mhl_mem_free()). For NULL strings, "" is assumed. * mhl_str_concat_2(const char* base,const char* one,const char* two) -> char* mhl_str_concat_3(const char* base,const char* one,const char* two,const char* three) -> char* mhl_str_concat_4(const char* base,const char* one,const char* two,const char* three,const char* four) -> char* mhl_str_concat_5(const char* base,const char* one,const char* two,const char* three,const char* four,const char* five) -> char* mhl_str_concat_6(const char* base,const char* one,const char* two,const char* three,const char* four,const char* five,const char* six) -> char* mhl_str_concat_7(const char* base,const char* one,const char* two,const char* three,const char* four,const char* five,const char* six,const char* seven) -> char* [INLINE-FUNC] Like str_concat_1() but adding more strings. * mhl_str_reverse(char* str) -> char* [INLINE-FUNC] Reverses the string in passed buffer and returns the buffer ptr itself. If NULL is passed, returns NULL. mhl/escape.h: Shell-style string escaping * mhl_shell_escape_toesc(char c) -> bool [MACRO-FUNC] returns true when given char has to be escaped * mhl_shell_escape_nottoesc(char c) -> bool [MACRO-FUNC] opposite of mhl_shell_escape_toesc() * mhl_shell_escape_dup(const char* s) -> char* [INLINE-FUNC] escapes an string and returns the result in a malloc()'ed chunk Passing NULL returns an empty malloc()ed string. * mhl_shell_unescape_buf(char* s) -> char* [INLINE-FUNC] unescapes the string into given buffer (changes buffer!) and returns ptr to the buffer itself. When NULL passed returns NULL. mhl/env.h: Environment variable helpers * mhl_getenv_dup(const char* n) -> char* [MACRO-FUNC] like getenv() but returns an strdup()'ed copy. When NULL passed, returns strdup("")