:: Re: [DNG] int essid_alloc is causin…
トップ ページ
このメッセージを削除
このメッセージに返信
著者: Rainer Weikusat
日付:  
To: dng
題目: Re: [DNG] int essid_alloc is causing valgrind to report a series of errors
Peter Olson <peabo@???> writes:
>> On October 14, 2015 at 3:20 PM Edward Bartolo <edbarx@???> wrote:
>>
>>
>> This is another part of the backend code where valgrind is saying:
>>
>> ==5501== 5 errors in context 1 of 3:
>> ==5501== Use of uninitialised value of size 8
>> ==5501==    at 0x5172AFC: ____strtod_l_internal (strtod_l.c:889)
>> ==5501==    by 0x403856: getRadiatingWifiList (automated_scanner.c:265)
>> ==5501==    by 0x403BDC: autoWirelessScanPlus (automated_scanner.c:386)
>> ==5501==    by 0x40400D: autoWirelessScanPlus_RN (automated_scanner.c:549)
>> ==5501==    by 0x402E2C: main (backend.c:251)
>> ==5501==  Uninitialised value was created by a stack allocation
>> ==5501==    at 0x4034BB: getRadiatingWifiList (automated_scanner.c:155)


[...]

>>                 tmp_wifi_quality->quality = strtod(tmpstr, NULL);

>
> You should probably investigate the area around line 155.


The code shouldn't use tmpstr in this way at all because

    The strtod(), strtof(), and strtold() functions convert the
    initial portion of the string pointed to by nptr to double,
    float, and long double representation, respectively.


        [...]


        If endptr is not NULL, a pointer to the character after the last
        character used in the conversion is stored in the location
        referenced by endptr.
        [strtod(3)]


In other words, strtod is capable of finding the end of the number to be
converted on its own.         


> =========================
>
> I have some other other comments.
>
>>                               tmp_wifi_quality = calloc(sizeof(wifi_quality),
>> 1);

>
> The canonical way to write this is
>
>>                               tmp_wifi_quality = calloc(1,
>> sizeof(wifi_quality));

>
> The calloc call is designed to return an array of N structures properly aligned
> for the requirements of the machine (for embedded pointers, as an
> example).


    The malloc() and calloc() functions return a pointer to the
    allocated memory that is suitably aligned for any kind of
    variable.
        [calloc(3)]


        The pointer returned if the allocation succeeds is suitably
    aligned so that it may be assigned to a pointer to any type of
    object and then used to access such an object or an array of
    such objects in the space allocated
        [ISO/IEC 9899:1999 (E), 7.20.3|1]