Skip to content

Commit

Permalink
Apply clang-format on crypto/* and compat/*
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa committed Sep 25, 2014
1 parent ea69592 commit cf42c36
Show file tree
Hide file tree
Showing 11 changed files with 589 additions and 458 deletions.
4 changes: 2 additions & 2 deletions src/compat/glibc_compat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ extern "C" void* memcpy(void* a, const void* b, size_t c)
return memmove(a, b, c);
}

extern "C" void __chk_fail (void) __attribute__((__noreturn__));
extern "C" void __chk_fail(void) __attribute__((__noreturn__));
extern "C" FDELT_TYPE __fdelt_warn(FDELT_TYPE a)
{
if (a >= FD_SETSIZE)
__chk_fail ();
__chk_fail();
return a / __NFDBITS;
}
extern "C" FDELT_TYPE __fdelt_chk(FDELT_TYPE) __attribute__((weak, alias("__fdelt_warn")));
14 changes: 7 additions & 7 deletions src/compat/glibc_sanity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
extern "C" void* memcpy(void* a, const void* b, size_t c);
void* memcpy_int(void* a, const void* b, size_t c)
{
return memcpy(a,b,c);
return memcpy(a, b, c);
}

namespace {
namespace
{
// trigger: Use the memcpy_int wrapper which calls our internal memcpy.
// A direct call to memcpy may be optimized away by the compiler.
// test: Fill an array with a sequence of integers. memcpy to a new empty array.
Expand All @@ -31,11 +32,10 @@ bool sanity_test_memcpy()
for (unsigned int i = 0; i != T; ++i)
memcpy_test[i] = i;

memcpy_int(memcpy_verify,memcpy_test,sizeof(memcpy_test));
memcpy_int(memcpy_verify, memcpy_test, sizeof(memcpy_test));

for (unsigned int i = 0; i != T; ++i)
{
if(memcpy_verify[i] != i)
for (unsigned int i = 0; i != T; ++i) {
if (memcpy_verify[i] != i)
return false;
}
return true;
Expand All @@ -51,7 +51,7 @@ bool sanity_test_fdelt()
fd_set fds;
FD_ZERO(&fds);
FD_SET(0, &fds);
return FD_ISSET(0,&fds);
return FD_ISSET(0, &fds);
}
#endif

Expand Down
19 changes: 9 additions & 10 deletions src/compat/glibcxx_compat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#define _GLIBCXX_USE_NOEXCEPT throw()
#endif

namespace std {

namespace std
{
const char* bad_exception::what() const throw()
{
return "std::bad_exception";
Expand All @@ -30,9 +30,8 @@ const char* bad_alloc::what() const throw()

namespace __detail
{
struct _List_node_base
{
void _M_hook(std::__detail::_List_node_base* const __position) throw () __attribute__((used))
struct _List_node_base {
void _M_hook(std::__detail::_List_node_base* const __position) throw() __attribute__((used))
{
_M_next = __position;
_M_prev = __position->_M_prev;
Expand Down Expand Up @@ -62,9 +61,9 @@ template ostream& __ostream_insert(ostream&, const char*, streamsize);
template istream& istream::_M_extract(long&);
template istream& istream::_M_extract(unsigned short&);

out_of_range::~out_of_range() _GLIBCXX_USE_NOEXCEPT { }
out_of_range::~out_of_range() _GLIBCXX_USE_NOEXCEPT {}

length_error::~length_error() _GLIBCXX_USE_NOEXCEPT { }
length_error::~length_error() _GLIBCXX_USE_NOEXCEPT {}

// Used with permission.
// See: https://github.com/madlib/madlib/commit/c3db418c0d34d6813608f2137fef1012ce03043d
Expand All @@ -85,11 +84,11 @@ void ctype<char>::_M_widen_init() const
}
}

void __throw_out_of_range_fmt(const char*, ...) __attribute__((__noreturn__));
void __throw_out_of_range_fmt(const char* err, ...)
void __throw_out_of_range_fmt(const char*, ...) __attribute__((__noreturn__));
void __throw_out_of_range_fmt(const char* err, ...)
{
// Safe and over-simplified version. Ignore the format and print it as-is.
__throw_out_of_range(err);
}

}// namespace std
} // namespace std
24 changes: 10 additions & 14 deletions src/compat/glibcxx_sanity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
#include <locale>
#include <stdexcept>

namespace{

namespace
{
// trigger: use ctype<char>::widen to trigger ctype<char>::_M_widen_init().
// test: convert a char from narrow to wide and back. Verify that the result
// matches the original.
bool sanity_test_widen(char testchar)
{
const std::ctype<char>& test(std::use_facet< std::ctype<char> >(std::locale()));
return test.narrow(test.widen(testchar),'b') == testchar;
const std::ctype<char>& test(std::use_facet<std::ctype<char> >(std::locale()));
return test.narrow(test.widen(testchar), 'b') == testchar;
}

// trigger: use list::push_back and list::pop_back to trigger _M_hook and
Expand All @@ -25,14 +25,13 @@ bool sanity_test_list(unsigned int size)
{
std::list<unsigned int> test;
for (unsigned int i = 0; i != size; ++i)
test.push_back(i+1);
test.push_back(i + 1);

if (test.size() != size)
return false;

while (!test.empty())
{
if(test.back() != test.size())
while (!test.empty()) {
if (test.back() != test.size())
return false;
test.pop_back();
}
Expand All @@ -47,15 +46,12 @@ bool sanity_test_list(unsigned int size)
bool sanity_test_range_fmt()
{
std::string test;
try
{
try {
test.at(1);
}
catch (const std::out_of_range&)
{
} catch (const std::out_of_range&) {
return true;
} catch (...) {
}
catch (...){}
return false;
}

Expand Down
55 changes: 40 additions & 15 deletions src/crypto/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
#include <endian.h>
#endif

uint32_t static inline ReadLE32(const unsigned char *ptr) {
uint32_t static inline ReadLE32(const unsigned char* ptr)
{
#if HAVE_DECL_LE32TOH == 1
return le32toh(*((uint32_t*)ptr));
#elif !defined(WORDS_BIGENDIAN)
Expand All @@ -23,8 +24,8 @@ uint32_t static inline ReadLE32(const unsigned char *ptr) {
#endif
}

uint64_t static inline ReadLE64(const unsigned char *ptr) {

uint64_t static inline ReadLE64(const unsigned char* ptr)
{
#if HAVE_DECL_LE64TOH == 1
return le64toh(*((uint64_t*)ptr));
#elif !defined(WORDS_BIGENDIAN)
Expand All @@ -35,36 +36,49 @@ uint64_t static inline ReadLE64(const unsigned char *ptr) {
#endif
}

void static inline WriteLE32(unsigned char *ptr, uint32_t x) {
void static inline WriteLE32(unsigned char* ptr, uint32_t x)
{
#if HAVE_DECL_HTOLE32 == 1
*((uint32_t*)ptr) = htole32(x);
#elif !defined(WORDS_BIGENDIAN)
*((uint32_t*)ptr) = x;
#else
ptr[3] = x >> 24; ptr[2] = x >> 16; ptr[1] = x >> 8; ptr[0] = x;
ptr[3] = x >> 24;
ptr[2] = x >> 16;
ptr[1] = x >> 8;
ptr[0] = x;
#endif
}

void static inline WriteLE64(unsigned char *ptr, uint64_t x) {
void static inline WriteLE64(unsigned char* ptr, uint64_t x)
{
#if HAVE_DECL_HTOLE64 == 1
*((uint64_t*)ptr) = htole64(x);
#elif !defined(WORDS_BIGENDIAN)
*((uint64_t*)ptr) = x;
#else
ptr[7] = x >> 56; ptr[6] = x >> 48; ptr[5] = x >> 40; ptr[4] = x >> 32;
ptr[3] = x >> 24; ptr[2] = x >> 16; ptr[1] = x >> 8; ptr[0] = x;
ptr[7] = x >> 56;
ptr[6] = x >> 48;
ptr[5] = x >> 40;
ptr[4] = x >> 32;
ptr[3] = x >> 24;
ptr[2] = x >> 16;
ptr[1] = x >> 8;
ptr[0] = x;
#endif
}

uint32_t static inline ReadBE32(const unsigned char *ptr) {
uint32_t static inline ReadBE32(const unsigned char* ptr)
{
#if HAVE_DECL_BE32TOH == 1
return be32toh(*((uint32_t*)ptr));
#else
return ((uint32_t)ptr[0] << 24 | (uint32_t)ptr[1] << 16 | (uint32_t)ptr[2] << 8 | (uint32_t)ptr[3]);
#endif
}

uint64_t static inline ReadBE64(const unsigned char *ptr) {
uint64_t static inline ReadBE64(const unsigned char* ptr)
{
#if HAVE_DECL_BE64TOH == 1
return be64toh(*((uint64_t*)ptr));
#else
Expand All @@ -73,20 +87,31 @@ uint64_t static inline ReadBE64(const unsigned char *ptr) {
#endif
}

void static inline WriteBE32(unsigned char *ptr, uint32_t x) {
void static inline WriteBE32(unsigned char* ptr, uint32_t x)
{
#if HAVE_DECL_HTOBE32 == 1
*((uint32_t*)ptr) = htobe32(x);
#else
ptr[0] = x >> 24; ptr[1] = x >> 16; ptr[2] = x >> 8; ptr[3] = x;
ptr[0] = x >> 24;
ptr[1] = x >> 16;
ptr[2] = x >> 8;
ptr[3] = x;
#endif
}

void static inline WriteBE64(unsigned char *ptr, uint64_t x) {
void static inline WriteBE64(unsigned char* ptr, uint64_t x)
{
#if HAVE_DECL_HTOBE64 == 1
*((uint64_t*)ptr) = htobe64(x);
#else
ptr[0] = x >> 56; ptr[1] = x >> 48; ptr[2] = x >> 40; ptr[3] = x >> 32;
ptr[4] = x >> 24; ptr[5] = x >> 16; ptr[6] = x >> 8; ptr[7] = x;
ptr[0] = x >> 56;
ptr[1] = x >> 48;
ptr[2] = x >> 40;
ptr[3] = x >> 32;
ptr[4] = x >> 24;
ptr[5] = x >> 16;
ptr[6] = x >> 8;
ptr[7] = x;
#endif
}

Expand Down
Loading

0 comments on commit cf42c36

Please sign in to comment.