URL:
<http://gna.org/bugs/?19388>
Summary: not a const (3)
Project: Freeciv
Submitted by: bit
Submitted on: Mi 01 Feb 2012 14:32:03 GMT
Category: None
Severity: 3 - Normal
Priority: 5 - Normal
Status: None
Assigned to: None
Originator Email:
Open/Closed: Open
Release: 2.3.1
Discussion Lock: Any
Operating System: None
Planned Release:
_______________________________________________________
Details:
file: shared.cpp
char scanin(const char **buf, char *delimiters, char *dest, int size)
delimiters is a const char*.
patch in shared.h too.
Now a dirty fix for that problem inside scanin.
(It's how the fix is meant, I don't like the redundant parts too)
[code]
{
char found = '?';
if (dest) {
/* in this part strpbrk operates on the non-const dest,
so the destination-pointer ptr must be non-const too
and is allowed to write (the nullbyte)
*/
char *ptr;
if (*buf == NULL || strlen(*buf) == 0 || size == 0) {
dest[0] = '\0';
*buf = NULL;
return '\0';
}
strncpy(dest, *buf, size-1);
dest[size-1] = '\0';
remove_leading_trailing_spaces(dest);
ptr = strpbrk(dest, delimiters);
if (ptr != NULL) {
found = *ptr;
*ptr = '\0';
remove_leading_trailing_spaces(dest);
*buf = strpbrk(*buf, delimiters);
if (*buf != NULL) {
(*buf)++; /* skip delimiter */
}
} else {
*buf = NULL;
}
} else {
/* in this part strpbrk operates on the const char **buf,
so the destination-pointer ptr must be const too.
in fact here is no write access.
*/
const char *ptr;
if (*buf == NULL || strlen(*buf) == 0 || size == 0) {
*buf = NULL;
return '\0';
}
/* Just skip ahead. */
ptr = strpbrk(*buf, delimiters);
if (ptr != NULL) {
found = *ptr;
*buf = strpbrk(*buf, delimiters);
if (*buf != NULL) {
(*buf)++; /* skip delimiter */
}
} else {
*buf = NULL;
}
}
return found;
}
[/code]
_______________________________________________________
Reply to this item at:
<http://gna.org/bugs/?19388>
_______________________________________________
Nachricht geschickt von/durch Gna!
http://gna.org/
_______________________________________________
Freeciv-dev mailing list
[email protected]
https://mail.gna.org/listinfo/freeciv-dev