Date: prev next · Thread: first prev next last
2012 Archives by date, by thread · List index


On 24/12/2012 18:08, Norbert Thiebaud wrote:
On Mon, Dec 24, 2012 at 8:59 AM, julien2412<serval2412@yahoo.fr>  wrote:
Hello,

In sal/osl/unx/security.c, I noticed these:
     278 sal_Bool SAL_CALL osl_getHomeDir(oslSecurity Security, rtl_uString
**pustrDirectory)
     279 {
     280     sal_Bool bRet=sal_False;
     281     sal_Char pszDirectory[PATH_MAX];
     282
     283     pszDirectory[0] = '\0';

     373 sal_Bool SAL_CALL osl_getConfigDir(oslSecurity Security, rtl_uString
**pustrDirectory)
     374 {
     375     sal_Bool bRet = sal_False;
     376     sal_Char pszDirectory[PATH_MAX];
     377
     378     pszDirectory[0] = '\0';

I'm not sure but I think it doesn't put the rest of the array to 0.
Would memsetting to 0 the whole array be right (and possibly useful)?
What issue are you trying to solve ? i'm not sure as to the purpose of
memsetting 512-1024 bytes
I heard/read that letting variable uninitialized could be dangerous, above all with C functions related to string/array of characters because \0 is the only checked element. So the goal was to initialize the whole array (instead of first element only) to be sure there's no problem. But perhaps only urban legend or I simply just misunderstood the point with string/array in C+ (more probably last one :-))
What about this too ?
sal_Char pszDirectory[PATH_MAX] = "";
It compiles but I wonder if it would be ok for every env
blanc-bonnet et bonnet-blanc :-)
for memset proposition and

sal_Char pszDirectory[PATH_MAX] = "";

ok because they put all the elements of the array to \0 but do you think it's "kif-kif" (:-)) too for:

pszDirectory[0] = '\0';

This last one seems to put only the first element of the array to \0, the situation I think, perhaps wrongly, that may be dangerous (see before comment)
although I don't know if the compiler is smart enough to avoid having
an actual literal string of len 0 rather than just putting 0 in the
first byte of the local variable.
That's the point, I don't know if there could be a trick or internal mechanism to think about C compilers of the different platforms.

iow it would not change anything 'functionally' and at best it would
be  a wash as far as generated code.
Ok, just a thought waiting by Xmas :-)

Norbert
Julien

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.