Changeset 99525be7e6268ba595d424f7f84e31716765f1fc

Show
Ignore:
Timestamp:
10/20/09 01:29:02 (5 weeks ago)
Author:
Anders Kaseorg <andersk@mit.edu>
git-author:
Anders Kaseorg <andersk@mit.edu> / 2009-10-19T23:29:35Z-0400
Parents:
6337cb5742f397a3db9201557de56be05c9394a1
Children:
3c428d48282cf713201d1675e0b568003c595d46
git-committer:
Anders Kaseorg <andersk@mit.edu> / 2009-10-20T01:29:02Z-0400
Message:
Use strtol without casting, to shut up gcc -Wcast-qual.

strtol should really have been two functions with types

  long int strtol(char *nptr, char **endptr, int base);
  long int strtol(const char *nptr, const char **endptr, int base);

but C doesn’t have overloading, so the real strtol has make a small
type safety compromise:

  long int strtol(const char *nptr, char **endptr, int base);

Such a compromise would be invisible in the return type (as it is with
char *strchr(const char *s, int c)), because char * may be implicitly
casted back to const char *.  But here char **endptr is an output
pointer argument, and we can’t pass it the address of a const char *.

Initially I rejected that compromise by casting endptr from the
address of a const char *.  But that makes gcc -Wcast-qual emit an
unnecessary warning, so let’s just use a char * instead.

</rant>

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • cmd.c

    r36486be r99525be  
    201201 
    202202  if (cmd->cmd_i_fn || cmd->cmd_ctxi_fn) { 
    203       const char *ep = "x"; 
     203      char *ep; 
    204204      if (argc != 2) { 
    205205        owl_function_makemsg("Wrong number of arguments for %s command.", argv[0]); 
    206206        return NULL; 
    207207      } 
    208       ival = strtol(argv[1], (char **)&ep, 10); 
     208      ival = strtol(argv[1], &ep, 10); 
    209209      if (*ep || ep==argv[1]) { 
    210210        owl_function_makemsg("Invalid argument '%s' for %s command.", argv[1], argv[0]); 
  • variable.c

    rde3f641 r99525be  
    905905int owl_variable_int_set_fromstring_default(owl_variable *v, const char *newval) { 
    906906  int i; 
    907   const char *ep = "x"; 
    908   i = strtol(newval, (char **)&ep, 10); 
     907  char *ep; 
     908  i = strtol(newval, &ep, 10); 
    909909  if (*ep || ep==newval) return(-1); 
    910910  return (v->set_fn(v, &i));