Skip to content

Commit

Permalink
Minor style changes and C99 issues (variable definitions after code).
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Jan 30, 2023
1 parent 40ff06b commit 8092d98
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 22 deletions.
10 changes: 5 additions & 5 deletions less.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
#include <limits.h>
#endif
#if HAVE_STDINT_H
# include <stdint.h>
#include <stdint.h>
#endif
#if HAVE_STDLIB_H
#include <stdlib.h>
Expand All @@ -81,16 +81,16 @@
#endif

#if HAVE_STDCKDINT_H
# include <stdckdint.h>
#include <stdckdint.h>
#else
/*
* These substitutes for C23 stdckdint macros do not set *R on overflow,
* and they assume A and B are nonnegative. That is good enough for us.
*/
# define ckd_add(r, a, b) help_ckd_add(r, a, b, sizeof *(r), signed_expr(*(r)))
# define ckd_mul(r, a, b) help_ckd_mul(r, a, b, sizeof *(r), signed_expr(*(r)))
#define ckd_add(r, a, b) help_ckd_add(r, a, b, sizeof *(r), signed_expr(*(r)))
#define ckd_mul(r, a, b) help_ckd_mul(r, a, b, sizeof *(r), signed_expr(*(r)))
/* True if the integer expression E, after promotion, is signed. */
# define signed_expr(e) ((TRUE ? 0 : e) - 1 < 0)
#define signed_expr(e) ((TRUE ? 0 : e) - 1 < 0)
#endif

#if defined UINTMAX_MAX
Expand Down
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public void * ecalloc(int count, unsigned int size)
void * p;

p = (void *) calloc(count, size);
if (!p)
if (p == NULL)
out_of_memory();
return p;
}
Expand Down
3 changes: 2 additions & 1 deletion optfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,8 @@ public void set_tabs(char *s, int len)
/* Start at 1 because tabstops[0] is always zero. */
for (i = 1; i < TABSTOP_MAX; )
{
int n = 0, v = FALSE;
int n = 0;
int v = FALSE;
for (; s < es && *s >= '0' && *s <= '9'; s++)
{
v |= ckd_mul(&n, n, 10);
Expand Down
8 changes: 6 additions & 2 deletions os.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,12 @@ public uintmax muldiv(uintmax val, uintmax num, uintmax den)
* Like round(val * (double) num / den), but without rounding error.
* Overflow cannot occur, so there is no need for floating point.
*/
uintmax q = val / den, r = val % den, qnum = q * num, rnum = r * num,
quot = qnum + rnum / den, rem = rnum % den;
uintmax q = val / den;
uintmax r = val % den;
uintmax qnum = q * num;
uintmax rnum = r * num;
uintmax quot = qnum + rnum / den;
uintmax rem = rnum % den;
return quot + (den / 2 < rem + (quot & ~den & 1));
}

Expand Down
26 changes: 13 additions & 13 deletions xbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,50 +90,50 @@ static int help_fixup(void *r, uintmax val, int rsize, int rsigned)
{
if (rsize == sizeof (int))
{
int *pr = r;
if (INT_MAX < val)
return TRUE;
int *pr = r;
*pr = val;
# ifdef LLONG_MAX
#ifdef LLONG_MAX
} else if (rsize == sizeof (long long))
{
long long *pr = r;
if (LLONG_MAX < val)
return TRUE;
long long *pr = r;
*pr = val;
# endif
# ifdef INTMAX_MAX
#endif
#ifdef INTMAX_MAX
} else if (rsize == sizeof (intmax_t)) {
intmax_t *pr = r;
if (INTMAX_MAX < val)
return TRUE;
intmax_t *pr = r;
*pr = val;
# endif
#endif
} else /* rsize == sizeof (long) */
{
long *pr = r;
if (LONG_MAX < val)
return TRUE;
long *pr = r;
*pr = val;
}
} else {
if (rsize == sizeof (unsigned)) {
unsigned *pr = r;
if (UINT_MAX < val)
return TRUE;
unsigned *pr = r;
*pr = val;
} else if (rsize == sizeof (unsigned long)) {
unsigned long *pr = r;
if (ULONG_MAX < val)
return TRUE;
unsigned long *pr = r;
*pr = val;
# ifdef ULLONG_MAX
#ifdef ULLONG_MAX
} else if (rsize == sizeof (unsigned long long)) {
long long *pr = r;
if (ULLONG_MAX < val)
return TRUE;
long long *pr = r;
*pr = val;
# endif
#endif
} else /* rsize == sizeof (uintmax) */
{
uintmax *pr = r;
Expand Down

0 comments on commit 8092d98

Please sign in to comment.