aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@member.fsf.org>2015-12-27 22:17:10 +0100
committerMattias Andrée <maandree@member.fsf.org>2015-12-27 22:17:10 +0100
commit9e08948192dec57de4c38097d58f301dec7d6b5d (patch)
tree1b8fd3a3dced1724551f1d24aaa3027fdfaa584b
parentfix warning (diff)
downloadslibc-9e08948192dec57de4c38097d58f301dec7d6b5d.tar.gz
slibc-9e08948192dec57de4c38097d58f301dec7d6b5d.tar.bz2
slibc-9e08948192dec57de4c38097d58f301dec7d6b5d.tar.xz
fix errors and warnings
Signed-off-by: Mattias Andrée <maandree@member.fsf.org>
-rw-r--r--include/slibc-human.h2
-rw-r--r--src/slibc-human/escape.c14
-rw-r--r--src/slibc-human/humanmode.c2
-rw-r--r--src/slibc-human/humansize.c12
-rw-r--r--src/slibc-human/machinemode.c4
-rw-r--r--src/slibc-human/unescape.c34
6 files changed, 35 insertions, 33 deletions
diff --git a/include/slibc-human.h b/include/slibc-human.h
index 4d4de69..e0423bc 100644
--- a/include/slibc-human.h
+++ b/include/slibc-human.h
@@ -439,7 +439,7 @@ char* unescape(char*, enum unescape_mode);
*
* @since Always.
*/
-char* escape(const char* restrict)
+char* escape(const char* restrict, int quote)
__GCC_ONLY(__attribute__((__malloc__, __warn_unused_result__)));
diff --git a/src/slibc-human/escape.c b/src/slibc-human/escape.c
index 4296715..e09c2aa 100644
--- a/src/slibc-human/escape.c
+++ b/src/slibc-human/escape.c
@@ -41,10 +41,10 @@
*
* @since Always.
*/
-char* escape(const char* restrict str, char quote)
+char* escape(const char* restrict str, int quote)
{
-#define OCTAL(s) (*w++ = '0' + ((c >> (s)) & 7))
-#define MODNUL(s) (((unsigned)((s)[0]) == 0xC0) && ((unsigned)((s)[1]) == 0x80))
+#define OCTAL(s) (*w++ = (char)('0' + ((c >> (s)) & 7)))
+#define MODNUL(s) (((unsigned char)((s)[0]) == 0xC0) && ((unsigned char)((s)[1]) == 0x80))
const char* restrict r;
char* restrict w;
@@ -65,7 +65,7 @@ char* escape(const char* restrict str, char quote)
return errno = EINVAL, NULL;
}
- for (r = str; (c = *r); r++)
+ for (r = str; (c = (unsigned char)*r); r++)
switch (c)
{
#define X(E, C) case C:
@@ -89,7 +89,7 @@ char* escape(const char* restrict str, char quote)
if (rc == NULL)
return NULL;
- for (r = str; (c = *r); r++)
+ for (r = str; (c = (unsigned char)*r); r++)
switch (c)
{
#define X(E, C) case C: *w++ = '\\', *w++ = E; break;
@@ -99,9 +99,9 @@ char* escape(const char* restrict str, char quote)
default:
*w++ = '\\';
if (MODNUL(r)) *w++ = '0', r++;
- else if (c == quote) *w++ = quote;
+ else if (c == quote) *w++ = (char)quote;
else if (c < ' ') OCTAL(6), OCTAL(3), OCTAL(0);
- else w[-1] = c;
+ else w[-1] = (char)c;
break;
}
diff --git a/src/slibc-human/humanmode.c b/src/slibc-human/humanmode.c
index 6288433..f7ee8b5 100644
--- a/src/slibc-human/humanmode.c
+++ b/src/slibc-human/humanmode.c
@@ -44,7 +44,7 @@ char* humanmode(char* restrict buffer, mode_t perm, enum humanmode_mode mode)
int name = mode & HUMANMODE_MASK;
char* w;
- if (mode & ~3)
+ if (mode & ~(mode_t)3)
return errno = EINVAL, NULL;
if (!mode)
mode = HUMANMODE_STAT;
diff --git a/src/slibc-human/humansize.c b/src/slibc-human/humansize.c
index abf02b3..1e57329 100644
--- a/src/slibc-human/humansize.c
+++ b/src/slibc-human/humansize.c
@@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <slibc-human.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <alloca.h>
@@ -69,7 +70,7 @@ static char* humansize_exact(char* buffer, size_t bufsize, enum humansize_mode m
const char* restrict prefixes, const size_t* restrict values, char* restrict buf)
{
size_t i, n = 0;
- char* new = NULL;
+ void* new = NULL;
int m, saved_errno;
if (detail == 0)
@@ -95,7 +96,7 @@ static char* humansize_exact(char* buffer, size_t bufsize, enum humansize_mode m
/* Ensure the buffer is large enougth. */
if (n + (size_t)m > bufsize / sizeof(char))
{
- bufsize = 7 * detail + strlen(interspacing) * (detail - 1) + 1;
+ bufsize = 7 * (size_t)detail + strlen(interspacing) * ((size_t)detail - 1) + 1;
new = malloc(bufsize *= sizeof(char));
if (new == NULL)
goto fail;
@@ -151,6 +152,7 @@ static char* humansize_round(char* buffer, size_t bufsize, enum humansize_mode m
double total = 0, dividend = 1;
size_t prefix = words - 1, i, n, det;
char* p;
+ void* new = NULL;
char c;
int m, saved_errno;
@@ -190,8 +192,8 @@ static char* humansize_round(char* buffer, size_t bufsize, enum humansize_mode m
det = (size_t)-detail;
if (det >= n)
det = n - 1;
- c = buffer[n - detail];
- for (i = n - detail; i < n; i++)
+ c = buffer[n + (size_t)-detail];
+ for (i = n + (size_t)-detail; i < n; i++)
buffer[i] = '0';
if (c >= '5')
{
@@ -275,7 +277,7 @@ char* humansize(char* buffer, size_t bufsize, size_t size, enum humansize_mode m
case 0:
case HUMANSIZE_SI:
div = 1000;
- prefixes[1] = 'k'
+ prefixes[1] = 'k';
break;
case HUMANSIZE_IEC:
diff --git a/src/slibc-human/machinemode.c b/src/slibc-human/machinemode.c
index 0dceddf..fc11ea9 100644
--- a/src/slibc-human/machinemode.c
+++ b/src/slibc-human/machinemode.c
@@ -73,7 +73,7 @@
* 1=can write, 2=can execute/list, 3=can execute/list or/and
* special, 4=special} to permissions bits map.
*/
-static mode_t bits[][] = {
+static mode_t bits[][5] = {
{S_IRUSR, S_IWUSR, S_IXUSR, S_ISUSR, S_ISUID},
{S_IRGRP, S_IWGRP, S_IXGRP, S_ISGRP, S_ISGID},
{S_IROTH, S_IWOTH, S_IXOTH, S_ISOTH, S_ISVTX},
@@ -120,7 +120,7 @@ static inline int partial_symbolic(mode_t* restrict mode, mode_t* restrict mask,
/* Get permissions. */
for (partial_or = 0; *str && (*str != ','); str++)
for (user = first; user < last; user++)
- BITS(*str, partial_or, j);
+ BITS(*str, partial_or, user);
/* Apply permissions. */
if (symbol != '-') or |= partial_or;
diff --git a/src/slibc-human/unescape.c b/src/slibc-human/unescape.c
index da08b9a..779a0e4 100644
--- a/src/slibc-human/unescape.c
+++ b/src/slibc-human/unescape.c
@@ -56,18 +56,18 @@ char* unescape(char* str, enum unescape_mode mode)
#define RANGE(a, c, z) (((a) <= (c)) && ((c) <= (z)))
#define CxC0(s, m) (*w++ = (char)((m) | (v >> (s))))
#define Cx80(s) (*w++ = (char)(0x80 | ((v >> (s)) & 0x3F)))
-#define NEXT_OCTAL(v) if (RANGE('0', r[1], '7')) v = (v << 3) | (r[1] - '0'), r++;
-#define PARSE_HEX(START, COND, v) \
- do for (i = START; COND; i++) { \
- char c = r[i]; \
- if (RANGE('0', c, '9')) c -= '0'; \
- else if (RANGE('a', c, 'f')) c -= 'a', c += 10; \
- else if (RANGE('A', c, 'F')) c -= 'A', c += 10; \
- else \
- goto unrecognised; \
- v = (v << 4) | (unsigned long int)c; \
- if (v > 0x10FFFFUL) \
- goto unrecognised; \
+#define NEXT_OCTAL(v) if (RANGE('0', r[1], '7')) v = (v << 3) | (unsigned long int)(r[1] - '0'), r++;
+#define PARSE_HEX(START, COND, v) \
+ do for (i = START; COND; i++) { \
+ char c = r[i]; \
+ if (RANGE('0', c, '9')) c = (char)(c - '0'); \
+ else if (RANGE('a', c, 'f')) c = (char)(c - 'a' + 10); \
+ else if (RANGE('A', c, 'F')) c = (char)(c - 'A' + 10); \
+ else \
+ goto unrecognised; \
+ v = (v << 4) | (unsigned long int)c; \
+ if (v > 0x10FFFFUL) \
+ goto unrecognised; \
} while (0)
#define UNRECOGNISED(c, action) \
if ( mode & UNESCAPE_EINVAL) goto invalid; \
@@ -87,9 +87,9 @@ char* unescape(char* str, enum unescape_mode mode)
char* w;
char* r;
- if (str == NULL) return errno = 0, NULL;
- if (mode & ~31) goto invalid;
- if (mode == 0) mode |= UNESCAPE_MOD_UTF8;
+ if (str == NULL) return errno = 0, NULL;
+ if (mode & ~(unsigned)31) goto invalid;
+ if (mode == 0) mode |= UNESCAPE_MOD_UTF8;
switch (mode & 7)
{
case 0:
@@ -126,7 +126,7 @@ char* unescape(char* str, enum unescape_mode mode)
break;
case '^':
- if (RANGE('@', r[1], '_')) *w++ = *++r - '@';
+ if (RANGE('@', r[1], '_')) *w++ = (char)(*++r - '@');
else
{
UNRECOGNISED(r[1], *w++ = '^');
@@ -147,7 +147,7 @@ char* unescape(char* str, enum unescape_mode mode)
default:
if (RANGE('0', *r, '7'))
{
- v = *r - '0';
+ v = (unsigned long int)(*r - '0');
NEXT_OCTAL(v);
NEXT_OCTAL(v);
UTF8();