[GRASS5] g.region G_usage() commented out?
Russell Nelson
nelson at crynwr.com
Mon May 20 09:50:54 EDT 2002
Glynn Clements writes:
> AFAICT, the code appears to be ensuring that the code processes the
> entire string, and not just some initial portion of it.
But tbuf[] is filled by copying characters from buf up to the first
null. Therefore, buf cannot contain any embedded nulls, and
strlen(buf) is going to be equal to strchr(tbuf, MARKER) - tbuf every
time. So why not just run up to the null? The only reason I can see
to have MARKER would be if you wanted to safely look at buf[i] and
buf[i+1] without first checking to see if buf[i] is a '\0'. The
original code didn't do that, but ahhhh, I see that I have introduced
a potential segfault. Revised patch, which actually is simpler and
easier to understand:
Index: src/libes/gis/ll_scan.c
===================================================================
RCS file: /home/grass/grassrepository/grass/src/libes/gis/ll_scan.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 ll_scan.c
--- src/libes/gis/ll_scan.c 29 Dec 1999 15:10:30 -0000 1.1.1.1
+++ src/libes/gis/ll_scan.c 20 May 2002 13:49:13 -0000
@@ -53,13 +53,9 @@
int G_llres_scan ( char *buf, double *res)
{
- char tbuf[100];
-
- sprintf (tbuf, "%se", buf);
- return scan_ll (tbuf, "we", res, 0);
+ return scan_ll (buf, NULL, res, 0);
}
-#define MARKER 1
static int scan_ll (
char *buf,
char *dir,
@@ -70,10 +66,6 @@
int d,m,s;
char ps[20], *pps;
double p, f;
- char tbuf[100];
-
- sprintf (tbuf, "%s%c", buf, MARKER); /* add a marker at end of string */
- buf = tbuf;
if (sscanf (buf, "%d:%d:%d.%[0123456789]%[^\n]", &d, &m, &s, ps, h) == 5)
{
@@ -117,13 +109,16 @@
G_strip (h);
- if (*result == 0.0 && *h == MARKER)
+ if (*result == 0.0 && *h == '\0')
return (1);
+ if (dir == NULL)
+ return *h == '\0';
+
if (*h >= 'A' && *h <= 'Z') *h += 'a' - 'A';
if (*h != dir[0] && *h != dir[1])
return 0;
- if (h[1] != MARKER)
+ if (h[1] != '\0')
return 0;
if (*h == dir[0] && *result != 0.0)
--
-russ nelson http://russnelson.com | Nelson's principle: when
Crynwr sells support for free software | PGPok | someone proposes a solution,
521 Pleasant Valley Rd. | +1 315 268 1925 voice | always ask for a definition
Potsdam, NY 13676-3213 | +1 315 268 9201 FAX | of the problem it solves.
More information about the grass-dev
mailing list