Skip to content

Commit

Permalink
Apply clang-tidy fixes to libc files
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipjohnston committed Dec 4, 2018
1 parent b3d6285 commit aa13fea
Show file tree
Hide file tree
Showing 26 changed files with 283 additions and 66 deletions.
6 changes: 5 additions & 1 deletion src/ctype/tolower.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
int tolower(int c)
{
if(isupper(c))
return c | 32;
{
{
return c | 32;
}
}
return c;
}
6 changes: 5 additions & 1 deletion src/ctype/toupper.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
int toupper(int c)
{
if(islower(c))
return c & 0x5f;
{
{
return c & 0x5f;
}
}
return c;
}
18 changes: 15 additions & 3 deletions src/errno/strerror.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,21 @@ char* strerror(int e)
}
}
for(i = 0; errid[i] && errid[i] != e; i++)
;
for(s = errmsg; i; s++, i--)
for(; *s; s++)
{
{
;
}
}
for(s = errmsg; i; s++, i--)
{
{
for(; *s; s++)
{
{
;
}
}
}
}
return (char*)(uintptr_t)s;
}
2 changes: 2 additions & 0 deletions src/exit/_Exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ __attribute__((weak, noreturn)) void _Exit(int ec)
(void)ec;

while(1)
{
;
}
}
12 changes: 10 additions & 2 deletions src/stdlib/heapsort.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,11 @@ int (*compar)(const void*, const void*);
char *base, *k, *p, *t;

if(nmemb <= 1)
return (0);
{
{
return (0);
}
}

if(!size)
{
Expand All @@ -157,7 +161,11 @@ int (*compar)(const void*, const void*);
}

if((k = malloc(size)) == NULL)
return (-1);
{
{
return (-1);
}
}

/*
* Items are numbered from 1 to nmemb, so offset from size bytes
Expand Down
12 changes: 10 additions & 2 deletions src/stdlib/heapsort_r.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ int (*compar)(void*, const void*, const void*);
char *base, *k, *p, *t;

if(nmemb <= 1)
return (0);
{
{
return (0);
}
}

if(!size)
{
Expand All @@ -158,7 +162,11 @@ int (*compar)(void*, const void*, const void*);
}

if((k = malloc(size)) == NULL)
return (-1);
{
{
return (-1);
}
}

/*
* Items are numbered from 1 to nmemb, so offset from size bytes
Expand Down
16 changes: 14 additions & 2 deletions src/stdlib/qsort.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ typedef int cmp_t(void*, const void*, const void*);
#else
typedef int cmp_t(const void*, const void*);
#endif
static inline char* med3(char*, char*, char*, cmp_t*, void*) __attribute__((always_inline));
static inline void swapfunc(char*, char*, size_t, size_t) __attribute__((always_inline));
static inline char* med3(char* a, char* b, char* c, cmp_t* cmd, void* thunk)
__attribute__((always_inline));
static inline void swapfunc(char* a, char* b, size_t n, size_t swaptype)
__attribute__((always_inline));

#define min(a, b) (a) < (b) ? a : b

Expand Down Expand Up @@ -142,8 +144,12 @@ static void _qsort(void* a, size_t n, size_t es,
if(n < 7)
{
for(pm = (char*)a + es; pm < (char*)a + n * es; pm += es)
{
for(pl = pm; pl > (char*)a && CMP(thunk, pl - es, pl) > 0; pl -= es)
{
swap(pl, pl - es);
}
}
return;
}
pm = (char*)a + (n / 2) * es;
Expand Down Expand Up @@ -187,7 +193,9 @@ static void _qsort(void* a, size_t n, size_t es,
pc -= es;
}
if(pb > pc)
{
break;
}
swap(pb, pc);
swap_cnt = 1;
pb += es;
Expand All @@ -204,6 +212,7 @@ static void _qsort(void* a, size_t n, size_t es,
{ /* Switch to insertion sort */
r = 1 + n / 4; /* n >= 7, so r >= 2 */
for(pm = (char*)a + es; pm < (char*)a + n * es; pm += es)
{
for(pl = pm; pl > (char*)a && CMP(thunk, pl - es, pl) > 0; pl -= es)
{
swap(pl, pl - es);
Expand All @@ -212,16 +221,19 @@ static void _qsort(void* a, size_t n, size_t es,
goto nevermind;
}
}
}
return;
}

nevermind:
if((r = (uintptr_t)pb - (uintptr_t)pa) > es)
{
#ifdef I_AM_QSORT_R
_qsort(a, r / es, es, thunk, cmp, depth_limit);
#else
_qsort(a, r / es, es, cmp, depth_limit);
#endif
}
if((r = (uintptr_t)pd - (uintptr_t)pc) > es)
{
/* Iterate rather than recurse to save stack space */
Expand Down
12 changes: 10 additions & 2 deletions src/stdlib/strtol.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ register int base;
c = *s++;
}
else if(c == '+')
c = *s++;
{
{
c = *s++;
}
}
if((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X'))
{
c = s[1];
Expand All @@ -127,7 +131,11 @@ register int base;
base = 2;
}
if(base == 0)
base = c == '0' ? 8 : 10;
{
{
base = c == '0' ? 8 : 10;
}
}

/*
* Compute the cutoff value between legal numbers and illegal
Expand Down
42 changes: 35 additions & 7 deletions src/stdlib/strtoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ long long int strtoll(const char* nptr, char** endptr, int base)
{
neg = 0;
if(c == '+')
c = *s++;
{
{
c = *s++;
}
}
}
if((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X'))
{
Expand All @@ -97,7 +101,11 @@ long long int strtoll(const char* nptr, char** endptr, int base)
base = 16;
}
if(base == 0)
base = c == '0' ? 8 : 10;
{
{
base = c == '0' ? 8 : 10;
}
}

/*
* Compute the cutoff value between legal numbers and illegal
Expand Down Expand Up @@ -132,15 +140,35 @@ long long int strtoll(const char* nptr, char** endptr, int base)
for(acc = 0, any = 0;; c = (unsigned char)*s++)
{
if(isdigit(c))
c -= '0';
{
{
c -= '0';
}
}
else if(isalpha(c))
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
{
{
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
}
}
else
break;
{
{
break;
}
}
if(c >= base)
break;
{
{
break;
}
}
if(any < 0)
continue;
{
{
continue;
}
}
if(neg)
{
if(acc < cutoff || (acc == cutoff && c > cutlim))
Expand Down
6 changes: 5 additions & 1 deletion src/stdlib/strtoul.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ register int base;
base = 2;
}
if(base == 0)
base = c == '0' ? 8 : 10;
{
{
base = c == '0' ? 8 : 10;
}
}
cutoff = (unsigned long)ULONG_MAX / (unsigned long)base;
cutlim = (int)((unsigned long)ULONG_MAX % (unsigned long)base);
for(acc = 0, any = 0;; c = *s++)
Expand Down
54 changes: 45 additions & 9 deletions src/stdlib/strtoull.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ unsigned long long strtoull(const char* __restrict nptr, char** __restrict endpt
{
neg = 0;
if(c == '+')
c = *s++;
{
{
c = *s++;
}
}
}
if((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X'))
{
Expand All @@ -75,27 +79,59 @@ unsigned long long strtoull(const char* __restrict nptr, char** __restrict endpt
base = 16;
}
if(base == 0)
base = c == '0' ? 8 : 10;
{
{
base = c == '0' ? 8 : 10;
}
}
acc = any = 0;
if(base < 2 || base > 36)
goto noconv;
{
{
goto noconv;
}
}

cutoff = ULLONG_MAX / (unsigned long long)base;
cutlim = (int)(ULLONG_MAX % (unsigned long long)base);
for(;; c = *s++)
{
if(c >= '0' && c <= '9')
c -= '0';
{
{
c -= '0';
}
}
else if(c >= 'A' && c <= 'Z')
c -= 'A' - 10;
{
{
c -= 'A' - 10;
}
}
else if(c >= 'a' && c <= 'z')
c -= 'a' - 10;
{
{
c -= 'a' - 10;
}
}
else
break;
{
{
break;
}
}
if(c >= base)
break;
{
{
break;
}
}
if(any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
any = -1;
{
{
any = -1;
}
}
else
{
any = 1;
Expand Down
Loading

3 comments on commit aa13fea

@johnwbyrd
Copy link

@johnwbyrd johnwbyrd commented on aa13fea Mar 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What the hell? Why does adding all the double-enclosed brackets make the code better? The whole point of this library is to make simple, sane choices. You can't prioritize clang-tidy over common sense. Change your clang-tidy flags instead of making the code less sane.

@phillipjohnston
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a clang format error that I've been slowly correcting. Don't have to be an ass about it.

@phillipjohnston
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a bad commit, human error, not related to clang-tidy.

Please sign in to comment.