[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] dfa: remove some useless casts
From: |
Jim Meyering |
Subject: |
[PATCH] dfa: remove some useless casts |
Date: |
Tue, 21 Jun 2011 10:39:59 +0200 |
In today's realloc-changing patch, I removed a cast.
There were others like that, and removing one of them
exposed a function (icatalloc) that improperly marked
its "old" parameter as "const". It may write through
that parameter via realloc, and the now-removed cast
suppressed a warning about that.
>From 4eddaace7e2ccf1ae47b6205b5b8359be9657fce Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Tue, 21 Jun 2011 10:24:07 +0200
Subject: [PATCH] dfa: remove some useless casts
* src/dfa.c (icatalloc): Change type of "old" parameter
from "char const *" to "char *".
Don't cast-away const on realloc argument.
Remove now-unnecessary const-discarding cast.
Don't (void)-cast strcpy result.
* src/dosbuf.c (undossify_input): Remove anachronistic
cast-to-"char *" of realloc argument.
---
src/dfa.c | 8 ++++----
src/dosbuf.c | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/dfa.c b/src/dfa.c
index 10825f7..f2cd198 100644
--- a/src/dfa.c
+++ b/src/dfa.c
@@ -3625,7 +3625,7 @@ dfafree (struct dfa *d)
'psi|epsilon' is likelier)? */
static char *
-icatalloc (char const *old, char const *new)
+icatalloc (char *old, char const *new)
{
char *result;
size_t oldsize, newsize;
@@ -3634,14 +3634,14 @@ icatalloc (char const *old, char const *new)
if (old == NULL)
oldsize = 0;
else if (newsize == 0)
- return (char *) old;
+ return old;
else oldsize = strlen(old);
if (old == NULL)
result = malloc(newsize + 1);
else
- result = realloc((void *) old, oldsize + newsize + 1);
+ result = realloc(old, oldsize + newsize + 1);
if (result != NULL && new != NULL)
- (void) strcpy(result + oldsize, new);
+ strcpy(result + oldsize, new);
return result;
}
diff --git a/src/dosbuf.c b/src/dosbuf.c
index 3c8bc27..2e9fbd1 100644
--- a/src/dosbuf.c
+++ b/src/dosbuf.c
@@ -124,7 +124,7 @@ undossify_input (char *buf, size_t buflen)
if (inp_map_idx >= dos_pos_map_size - 1)
{
dos_pos_map_size = inp_map_idx ? inp_map_idx * 2 : 1000;
- dos_pos_map = xrealloc((char *)dos_pos_map,
+ dos_pos_map = xrealloc(dos_pos_map,
dos_pos_map_size *
sizeof(struct dos_map));
}
--
1.7.6.rc2.295.gb63f3
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] dfa: remove some useless casts,
Jim Meyering <=