diff --git a/src/include/FlashString/Map.hpp b/src/include/FlashString/Map.hpp index a735c64..c937f53 100644 --- a/src/include/FlashString/Map.hpp +++ b/src/include/FlashString/Map.hpp @@ -123,7 +123,7 @@ class Map : public Object, Pair> * @brief Get a map entry by index, if it exists * @note Result validity can be checked using if() */ - const Pair valueAt(unsigned index) const + FSTR_ALIGN32 const Pair valueAt(unsigned index) const { if(index >= this->length()) { return Pair::empty(); @@ -139,7 +139,7 @@ class Map : public Object, Pair> * @retval int If key isn't found, return -1 */ template - typename std::enable_if::value, int>::type indexOf(const TRefKey& key) const + FSTR_ALIGN32 typename std::enable_if::value, int>::type indexOf(const TRefKey& key) const { auto p = this->data(); auto len = this->length(); @@ -159,8 +159,8 @@ class Map : public Object, Pair> * @retval int If key isn't found, return -1 */ template - typename std::enable_if::value, int>::type indexOf(const TRefKey& key, - bool ignoreCase = true) const + FSTR_ALIGN32 typename std::enable_if::value, int>::type + indexOf(const TRefKey& key, bool ignoreCase = true) const { auto p = this->data(); auto len = this->length(); diff --git a/src/include/FlashString/MapPair.hpp b/src/include/FlashString/MapPair.hpp index d18096b..3ce32ba 100644 --- a/src/include/FlashString/MapPair.hpp +++ b/src/include/FlashString/MapPair.hpp @@ -62,7 +62,8 @@ template class MapPair /** * @brief Get the key (non-class key types) */ - template typename std::enable_if::value, KeyType>::type key() const + template + FSTR_ALIGN32 typename std::enable_if::value, KeyType>::type key() const { // Ensure access is aligned for 1/2 byte keys return readValue(&key_); @@ -72,7 +73,7 @@ template class MapPair * @brief Get the key (String key type) */ template - typename std::enable_if::value, const KeyType&>::type key() const + FSTR_ALIGN32 typename std::enable_if::value, const KeyType&>::type key() const { return (key_ == nullptr) ? String::empty() : *key_; } diff --git a/src/include/FlashString/ObjectIterator.hpp b/src/include/FlashString/ObjectIterator.hpp index 81fe198..d87db96 100644 --- a/src/include/FlashString/ObjectIterator.hpp +++ b/src/include/FlashString/ObjectIterator.hpp @@ -92,8 +92,9 @@ template class ObjectIterator * @brief Accessor returns a reference for pointer-type elements */ template - typename std::enable_if::value, const typename std::remove_pointer::type&>::type - operator*() const + FSTR_ALIGN32 + typename std::enable_if::value, const typename std::remove_pointer::type&>::type + operator*() const { auto ptr = data[index]; return ptr ? *ptr : std::remove_pointer::type::empty(); diff --git a/src/include/FlashString/Utility.hpp b/src/include/FlashString/Utility.hpp index 2644bed..a130121 100644 --- a/src/include/FlashString/Utility.hpp +++ b/src/include/FlashString/Utility.hpp @@ -141,7 +141,7 @@ template FSTR_INLINE typename std::enable_if::ty return static_cast(pgm_read_word(ptr)); } -template FSTR_INLINE typename std::enable_if::type readValue(const T* ptr) +template FSTR_ALIGN32 FSTR_INLINE typename std::enable_if::type readValue(const T* ptr) { union { uint32_t u32; diff --git a/src/include/FlashString/Vector.hpp b/src/include/FlashString/Vector.hpp index a3a7236..e91481b 100644 --- a/src/include/FlashString/Vector.hpp +++ b/src/include/FlashString/Vector.hpp @@ -170,7 +170,7 @@ template class Vector : public Object, con return printer().printTo(p); } - FSTR_INLINE static const ObjectType& unsafeValueAt(const DataPtrType dataptr, unsigned index) + FSTR_ALIGN32 static const ObjectType& unsafeValueAt(const DataPtrType dataptr, unsigned index) { auto ptr = dataptr[index]; return ptr ? *ptr : ObjectType::empty(); diff --git a/src/include/FlashString/config.hpp b/src/include/FlashString/config.hpp index 4836abc..9d624d4 100644 --- a/src/include/FlashString/config.hpp +++ b/src/include/FlashString/config.hpp @@ -29,6 +29,7 @@ #define FSTR_NOINLINE __attribute__((noinline)) #define FSTR_ALIGNED __attribute__((aligned(4))) #define FSTR_PACKED __attribute__((packed)) +#define FSTR_ALIGN32 __attribute__((no_sanitize("alignment"))) #ifdef __clang__ // Clang has a habit of throwing stuff away we want