Changeset 99525be


Ignore:
Timestamp:
Oct 20, 2009, 1:29:02 AM (12 years ago)
Author:
Anders Kaseorg <andersk@mit.edu>
Branches:
master, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
3c428d4
Parents:
6337cb5
git-author:
Anders Kaseorg <andersk@mit.edu> (10/19/09 23:29:35)
git-committer:
Anders Kaseorg <andersk@mit.edu> (10/20/09 01:29:02)
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 edited

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));
Note: See TracChangeset for help on using the changeset viewer.