[GRASS5] PATCH: alloc_cell.c
Glynn Clements
glynn at gclements.plus.com
Tue Oct 18 10:56:09 EDT 2005
Brad Douglas wrote:
> Any objections to me applying this patch to keep consistent with size_t
> *alloc() types?
Have you verified that nothing which calls G_raster_size() is relying
upon the return value being signed?
The issue is that if either operand to an arithmetic operation is
unsigned, the result is unsigned. This could be a problem if something
is multiplying a potentially-negative index by the result of
G_raster_size(), particularly if the result is promoted (explicitly or
implicitly) to a long on platforms where long is 64 bits:
$ cat foo.c
#include <stdio.h>
int main(void)
{
int x = -5;
int k1 = 2;
unsigned int k2 = 2;
/* my longs are only 32 bits, so use long long instead */
long long y1 = x * k1;
long long y2 = x * k2;
printf("y1 = %lld\ny2 = %lld\n", y1, y2);
return 0;
}
$ cc foo.c
$ ./a.out
y1 = -10
y2 = 4294967286
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list