mc/mhl
Sergei Trofimovich e48cb7c89f mhl: added mhl_strmove() function (memmove semantics)
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>
2009-01-30 09:31:28 +02:00
..
.gitignore Add .gitignore to mhl dir. 2009-01-14 13:21:58 +02:00
env.h renamed ../mhl/mhl* to <mhl/...> 2009-01-19 02:31:04 +01:00
escape.h introduced new type SHELL_ESCAPED_STR for more type safety 2009-01-27 22:27:06 +01:00
memory.h renamed ../mhl/mhl* to <mhl/...> 2009-01-19 02:31:04 +01:00
README Corrected names of the header files in the README for mhl 2009-01-23 20:07:32 +01:00
strhash.h renamed ../mhl/mhl* to <mhl/...> 2009-01-19 02:31:04 +01:00
string.h mhl: added mhl_strmove() function (memmove semantics) 2009-01-30 09:31:28 +02:00
types.h added mhl/types.h which defines bool enum, escape.h now using this type 2009-01-27 21:53:41 +01:00

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("")