[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [gpsd-dev] wsg_separation Issue
From: |
Beat Bolli |
Subject: |
Re: [gpsd-dev] wsg_separation Issue |
Date: |
Sun, 06 May 2012 14:14:10 +0200 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 |
On 06.05.12 02:13, Gary E. Miller wrote:
> Yo Beat!
>
> On Sat, 05 May 2012 23:23:13 +0200
> Beat Bolli <address@hidden> wrote:
>
>> On 05.05.12 21:38, Gary E. Miller wrote:
>>> On Fri, 4 May 2012 09:51:38 -0400
>>> "Bywater, Rick (SA-1)" <address@hidden> wrote:
>>>
>>>> I was running Coverity on gpsd-2.39 and it complained about an
>>>> array-bounds issue in geoid.c in the function wsg84_separation.
>
>> The current code is still wrong IMO:
>>
>> ilat = (int)floor((90. + lat) / 10);
>> ilon = (int)floor((180. + lon) / 10);
>>
>> /* sanity checks to prevent segfault on bad data */
>> if ((ilat > 90) || (ilat < -90)) {
>> return 0.0;
>> }
>> if ((ilon > 180) || (ilon < -180)) {
>> return 0.0;
>> }
>>
>> ilat and ilon are offset so as to be >= 0, but the subsequent test
>> checks the original degree range without offset or divisor. Checking
>> lat and lon above the i{lat,lon} calculation should work.
>
> Seems to me that keeping the sanity test on the integer, rather than,
> the float, is the way to go. So I think you are suggesting the test
> should be:
>
> if ((ilat > 18) || (ilat < 0)) {
> return 0.0;
> }
> if ((ilon > 36) || (ilon < 0)) {
> return 0.0;
> }
>
> Do I have it right?
I'd reuse the GEOID_ROW and GEOID_COL constants and merge the two ifs:
/* sanity checks to prevent segfault on bad data */
if ((ilat >= GEOID_ROW) || (ilat < 0) ||
(ilon >= GEOID_COL) || (ilon < 0))
return 0.0;
But other than that, it looks fine.
Regards,
Beat
--
mail: echo '<address@hidden>' | tr -d '[A-S]'
pgp: 0x506A903A; 49D5 794A EA77 F907 764F D89E 304B 93CF 506A 903A
gsm: 4.7.7.6.0.7.7.9.7.1.4.e164.arpa
icbm: 47.0452 N, 7.2715 E
"It takes love over gold, and mind over matter" -- Dire Straits
signature.asc
Description: OpenPGP digital signature
Re: [gpsd-dev] wsg_separation Issue, Eric S. Raymond, 2012/05/06
- Re: [gpsd-dev] wsg_separation Issue, Bywater, Rick (SA-1), 2012/05/07
- Re: [gpsd-dev] wsg_separation Issue, Eric S. Raymond, 2012/05/08
- Re: [gpsd-dev] wsg_separation Issue, Bywater, Rick (SA-1), 2012/05/09
- Re: [gpsd-dev] wsg_separation Issue, Dave Hart, 2012/05/09
- Re: [gpsd-dev] wsg_separation Issue, Eric S. Raymond, 2012/05/10
- Re: [gpsd-dev] wsg_separation Issue, Bywater, Rick (SA-1), 2012/05/10
- Re: [gpsd-dev] wsg_separation Issue, Eric S. Raymond, 2012/05/09