mirror of
https://github.com/serge1/ELFIO.git
synced 2025-04-16 05:42:31 +00:00
Use more portable function memchr()
Use more portable memchr() function instead of strnlen() which is not in ISO standard
This commit is contained in:
parent
8ae6cec5d6
commit
089160c40e
@ -45,8 +45,8 @@ template <class S> class string_section_accessor_template
|
|||||||
if ( string_section ) {
|
if ( string_section ) {
|
||||||
const char* data = string_section->get_data();
|
const char* data = string_section->get_data();
|
||||||
if ( index < string_section->get_size() && nullptr != data ) {
|
if ( index < string_section->get_size() && nullptr != data ) {
|
||||||
size_t string_length =
|
size_t string_length = strnlength(
|
||||||
strnlen( data + index, string_section->get_size() - index );
|
data + index, string_section->get_size() - index );
|
||||||
if ( string_length < ( string_section->get_size() - index ) )
|
if ( string_length < ( string_section->get_size() - index ) )
|
||||||
return data + index;
|
return data + index;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ THE SOFTWARE.
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
#define ELFIO_GET_ACCESS_DECL( TYPE, NAME ) virtual TYPE get_##NAME() const = 0
|
#define ELFIO_GET_ACCESS_DECL( TYPE, NAME ) virtual TYPE get_##NAME() const = 0
|
||||||
|
|
||||||
@ -259,6 +260,13 @@ inline void adjust_stream_size( std::ostream& stream, std::streamsize offset )
|
|||||||
stream.seekp( offset );
|
stream.seekp( offset );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
inline static size_t strnlength( const char* s, size_t n )
|
||||||
|
{
|
||||||
|
const char* found = (const char*)std::memchr( s, '\0', n );
|
||||||
|
return found ? (size_t)( found - s ) : n;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Consumers should write an implementation of this class and pass an instance of it to the ELFIO::elfio constructor.
|
* Consumers should write an implementation of this class and pass an instance of it to the ELFIO::elfio constructor.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user