Skip to content

Commit 66ab95e

Browse files
committedJun 27, 2024·
Suppress santize alignment warnings on 64-bit builds
1 parent 8685d62 commit 66ab95e

File tree

6 files changed

+13
-10
lines changed

6 files changed

+13
-10
lines changed
 

‎src/include/FlashString/Map.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class Map : public Object<Map<KeyType, ContentType>, Pair>
123123
* @brief Get a map entry by index, if it exists
124124
* @note Result validity can be checked using if()
125125
*/
126-
const Pair valueAt(unsigned index) const
126+
FSTR_ALIGN32 const Pair valueAt(unsigned index) const
127127
{
128128
if(index >= this->length()) {
129129
return Pair::empty();
@@ -139,7 +139,7 @@ class Map : public Object<Map<KeyType, ContentType>, Pair>
139139
* @retval int If key isn't found, return -1
140140
*/
141141
template <typename TRefKey, typename T = KeyType>
142-
typename std::enable_if<!std::is_class<T>::value, int>::type indexOf(const TRefKey& key) const
142+
FSTR_ALIGN32 typename std::enable_if<!std::is_class<T>::value, int>::type indexOf(const TRefKey& key) const
143143
{
144144
auto p = this->data();
145145
auto len = this->length();
@@ -159,8 +159,8 @@ class Map : public Object<Map<KeyType, ContentType>, Pair>
159159
* @retval int If key isn't found, return -1
160160
*/
161161
template <typename TRefKey, typename T = KeyType>
162-
typename std::enable_if<std::is_same<T, String>::value, int>::type indexOf(const TRefKey& key,
163-
bool ignoreCase = true) const
162+
FSTR_ALIGN32 typename std::enable_if<std::is_same<T, String>::value, int>::type
163+
indexOf(const TRefKey& key, bool ignoreCase = true) const
164164
{
165165
auto p = this->data();
166166
auto len = this->length();

‎src/include/FlashString/MapPair.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ template <typename KeyType, class ContentType> class MapPair
6262
/**
6363
* @brief Get the key (non-class key types)
6464
*/
65-
template <typename T = KeyType> typename std::enable_if<!std::is_class<T>::value, KeyType>::type key() const
65+
template <typename T = KeyType>
66+
FSTR_ALIGN32 typename std::enable_if<!std::is_class<T>::value, KeyType>::type key() const
6667
{
6768
// Ensure access is aligned for 1/2 byte keys
6869
return readValue<KeyType>(&key_);
@@ -72,7 +73,7 @@ template <typename KeyType, class ContentType> class MapPair
7273
* @brief Get the key (String key type)
7374
*/
7475
template <typename T = KeyType>
75-
typename std::enable_if<std::is_same<T, String>::value, const KeyType&>::type key() const
76+
FSTR_ALIGN32 typename std::enable_if<std::is_same<T, String>::value, const KeyType&>::type key() const
7677
{
7778
return (key_ == nullptr) ? String::empty() : *key_;
7879
}

‎src/include/FlashString/ObjectIterator.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ template <class ObjectType, typename ElementType> class ObjectIterator
9292
* @brief Accessor returns a reference for pointer-type elements
9393
*/
9494
template <typename T = ElementType>
95-
typename std::enable_if<std::is_pointer<T>::value, const typename std::remove_pointer<ElementType>::type&>::type
96-
operator*() const
95+
FSTR_ALIGN32
96+
typename std::enable_if<std::is_pointer<T>::value, const typename std::remove_pointer<ElementType>::type&>::type
97+
operator*() const
9798
{
9899
auto ptr = data[index];
99100
return ptr ? *ptr : std::remove_pointer<ElementType>::type::empty();

‎src/include/FlashString/Utility.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ template <typename T> FSTR_INLINE typename std::enable_if<sizeof(T) == 2, T>::ty
141141
return static_cast<T>(pgm_read_word(ptr));
142142
}
143143

144-
template <typename T> FSTR_INLINE typename std::enable_if<sizeof(T) == 4, T>::type readValue(const T* ptr)
144+
template <typename T> FSTR_ALIGN32 FSTR_INLINE typename std::enable_if<sizeof(T) == 4, T>::type readValue(const T* ptr)
145145
{
146146
union {
147147
uint32_t u32;

‎src/include/FlashString/Vector.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ template <class ObjectType> class Vector : public Object<Vector<ObjectType>, con
170170
return printer().printTo(p);
171171
}
172172

173-
FSTR_INLINE static const ObjectType& unsafeValueAt(const DataPtrType dataptr, unsigned index)
173+
FSTR_ALIGN32 static const ObjectType& unsafeValueAt(const DataPtrType dataptr, unsigned index)
174174
{
175175
auto ptr = dataptr[index];
176176
return ptr ? *ptr : ObjectType::empty();

‎src/include/FlashString/config.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#define FSTR_NOINLINE __attribute__((noinline))
3030
#define FSTR_ALIGNED __attribute__((aligned(4)))
3131
#define FSTR_PACKED __attribute__((packed))
32+
#define FSTR_ALIGN32 __attribute__((no_sanitize("alignment")))
3233

3334
#ifdef __clang__
3435
// Clang has a habit of throwing stuff away we want

0 commit comments

Comments
 (0)