Re: code style in the vfs

Leonard den Ottolander wrote:
Well something like that. slash can be modified and path with it. Of
course there is merit in catching such cases. But I am not sure if
introducing the macros defined by Roland into HEAD at this point is a
good idea. Let's first do it in a separate branch, substitute all
strrchrs by mod_strrchrs where appropriate, and merge once everything is
fixed and properly tested.

That's what I did yesterday. I have #defined the functions {mem,str}{r,}chr, strpbrk, str{case,}str, gettext and getenv to return a const char *.

The result was that they were almost always used correctly. The few places where they weren't had mostly been introduced by me adding the "const" qualifier without thinking further. These places have been corrected. But it shouldn't hurt if someone else takes a look at it, too.

I will keep the additional #include file I created for it, and will enable it from time to time against HEAD. If you also want to try, just #include "constwarns.h" (attachment #1) at the end of src/global.h.

If you know of some other functions that cast-away the const qualifier, please let me know.


#include <string.h>

#undef strchr
#define strchr(m_str, m_chr) (const char *) (strchr) (m_str, m_chr)

#undef strrchr
#define strrchr(m_str, m_chr) (const char *) (strrchr) (m_str, m_chr)

#undef memchr
#define memchr(m_mem, m_chr) (const char *) (memchr) (m_mem, m_chr)

#undef memrchr
#define memrchr(m_mem, m_chr) (const char *) (memrchr) (m_mem, m_chr)

#undef strpbrk
#define strpbrk(m_str1, m_str2) (const char *) (strpbrk) (m_str1, m_str2)

#undef strstr
#define strstr(m_str1, m_str2) (const char *) (strstr) (m_str1, m_str2)

#undef strcasestr
#define strcasestr(m_str1, m_str2) (const char *) (strcasestr) (m_str1, m_str2)

#undef gettext
#define gettext(m_str) (const char *) (gettext) (m_str)

#undef getenv
#define getenv(m_str) (const char *) (getenv) (m_str)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]