Skip to content

Commit

Permalink
Change the return type of the 2Data functions to size_t.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinbackhouse authored and neheb committed Aug 1, 2022
1 parent 1d0530f commit 4410f46
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
18 changes: 9 additions & 9 deletions include/exiv2/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,47 +277,47 @@ EXIV2API std::istream& operator>>(std::istream& is, URational& r);
@brief Convert an unsigned short to data, write the data to the buffer,
return number of bytes written.
*/
EXIV2API long us2Data(byte* buf, uint16_t s, ByteOrder byteOrder);
EXIV2API size_t us2Data(byte* buf, uint16_t s, ByteOrder byteOrder);
/*!
@brief Convert an unsigned long to data, write the data to the buffer,
return number of bytes written.
*/
EXIV2API long ul2Data(byte* buf, uint32_t l, ByteOrder byteOrder);
EXIV2API size_t ul2Data(byte* buf, uint32_t l, ByteOrder byteOrder);
/*!
@brief Convert an uint64_t to data, write the data to the buffer,
return number of bytes written.
*/
EXIV2API long ull2Data(byte* buf, uint64_t l, ByteOrder byteOrder);
EXIV2API size_t ull2Data(byte* buf, uint64_t l, ByteOrder byteOrder);
/*!
@brief Convert an unsigned rational to data, write the data to the buffer,
return number of bytes written.
*/
EXIV2API long ur2Data(byte* buf, URational l, ByteOrder byteOrder);
EXIV2API size_t ur2Data(byte* buf, URational l, ByteOrder byteOrder);
/*!
@brief Convert a signed short to data, write the data to the buffer,
return number of bytes written.
*/
EXIV2API long s2Data(byte* buf, int16_t s, ByteOrder byteOrder);
EXIV2API size_t s2Data(byte* buf, int16_t s, ByteOrder byteOrder);
/*!
@brief Convert a signed long to data, write the data to the buffer,
return number of bytes written.
*/
EXIV2API long l2Data(byte* buf, int32_t l, ByteOrder byteOrder);
EXIV2API size_t l2Data(byte* buf, int32_t l, ByteOrder byteOrder);
/*!
@brief Convert a signed rational to data, write the data to the buffer,
return number of bytes written.
*/
EXIV2API long r2Data(byte* buf, Rational l, ByteOrder byteOrder);
EXIV2API size_t r2Data(byte* buf, Rational l, ByteOrder byteOrder);
/*!
@brief Convert a single precision floating point (IEEE 754 binary32) float
to data, write the data to the buffer, return number of bytes written.
*/
EXIV2API long f2Data(byte* buf, float f, ByteOrder byteOrder);
EXIV2API size_t f2Data(byte* buf, float f, ByteOrder byteOrder);
/*!
@brief Convert a double precision floating point (IEEE 754 binary64) double
to data, write the data to the buffer, return number of bytes written.
*/
EXIV2API long d2Data(byte* buf, double d, ByteOrder byteOrder);
EXIV2API size_t d2Data(byte* buf, double d, ByteOrder byteOrder);

/*!
@brief Print len bytes from buf in hex and ASCII format to the given
Expand Down
18 changes: 9 additions & 9 deletions include/exiv2/value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1397,69 +1397,69 @@ inline double getValue(const byte* buf, ByteOrder byteOrder) {
@return The number of bytes written to the buffer.
*/
template <typename T>
long toData(byte* buf, T t, ByteOrder byteOrder);
size_t toData(byte* buf, T t, ByteOrder byteOrder);
/*!
@brief Specialization to write an unsigned short to the data buffer.
Return the number of bytes written.
*/
template <>
inline long toData(byte* buf, uint16_t t, ByteOrder byteOrder) {
inline size_t toData(byte* buf, uint16_t t, ByteOrder byteOrder) {
return us2Data(buf, t, byteOrder);
}
/*!
@brief Specialization to write an unsigned long to the data buffer.
Return the number of bytes written.
*/
template <>
inline long toData(byte* buf, uint32_t t, ByteOrder byteOrder) {
inline size_t toData(byte* buf, uint32_t t, ByteOrder byteOrder) {
return ul2Data(buf, t, byteOrder);
}
/*!
@brief Specialization to write an unsigned rational to the data buffer.
Return the number of bytes written.
*/
template <>
inline long toData(byte* buf, URational t, ByteOrder byteOrder) {
inline size_t toData(byte* buf, URational t, ByteOrder byteOrder) {
return ur2Data(buf, t, byteOrder);
}
/*!
@brief Specialization to write a signed short to the data buffer.
Return the number of bytes written.
*/
template <>
inline long toData(byte* buf, int16_t t, ByteOrder byteOrder) {
inline size_t toData(byte* buf, int16_t t, ByteOrder byteOrder) {
return s2Data(buf, t, byteOrder);
}
/*!
@brief Specialization to write a signed long to the data buffer.
Return the number of bytes written.
*/
template <>
inline long toData(byte* buf, int32_t t, ByteOrder byteOrder) {
inline size_t toData(byte* buf, int32_t t, ByteOrder byteOrder) {
return l2Data(buf, t, byteOrder);
}
/*!
@brief Specialization to write a signed rational to the data buffer.
Return the number of bytes written.
*/
template <>
inline long toData(byte* buf, Rational t, ByteOrder byteOrder) {
inline size_t toData(byte* buf, Rational t, ByteOrder byteOrder) {
return r2Data(buf, t, byteOrder);
}
/*!
@brief Specialization to write a float to the data buffer.
Return the number of bytes written.
*/
template <>
inline long toData(byte* buf, float t, ByteOrder byteOrder) {
inline size_t toData(byte* buf, float t, ByteOrder byteOrder) {
return f2Data(buf, t, byteOrder);
}
/*!
@brief Specialization to write a double to the data buffer.
Return the number of bytes written.
*/
template <>
inline long toData(byte* buf, double t, ByteOrder byteOrder) {
inline size_t toData(byte* buf, double t, ByteOrder byteOrder) {
return d2Data(buf, t, byteOrder);
}

Expand Down
22 changes: 11 additions & 11 deletions src/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ double getDouble(const byte* buf, ByteOrder byteOrder) {
return u.d_;
}

long us2Data(byte* buf, uint16_t s, ByteOrder byteOrder) {
size_t us2Data(byte* buf, uint16_t s, ByteOrder byteOrder) {
if (byteOrder == littleEndian) {
buf[0] = static_cast<byte>(s & 0x00ffU);
buf[1] = static_cast<byte>((s & 0xff00U) >> 8);
Expand All @@ -342,7 +342,7 @@ long us2Data(byte* buf, uint16_t s, ByteOrder byteOrder) {
return 2;
}

long ul2Data(byte* buf, uint32_t l, ByteOrder byteOrder) {
size_t ul2Data(byte* buf, uint32_t l, ByteOrder byteOrder) {
if (byteOrder == littleEndian) {
buf[0] = static_cast<byte>(l & 0x000000ffU);
buf[1] = static_cast<byte>((l & 0x0000ff00U) >> 8);
Expand All @@ -357,7 +357,7 @@ long ul2Data(byte* buf, uint32_t l, ByteOrder byteOrder) {
return 4;
}

long ull2Data(byte* buf, uint64_t l, ByteOrder byteOrder) {
size_t ull2Data(byte* buf, uint64_t l, ByteOrder byteOrder) {
if (byteOrder == littleEndian) {
for (size_t i = 0; i < 8; i++) {
buf[i] = static_cast<byte>(l & 0xff);
Expand All @@ -372,13 +372,13 @@ long ull2Data(byte* buf, uint64_t l, ByteOrder byteOrder) {
return 8;
}

long ur2Data(byte* buf, URational l, ByteOrder byteOrder) {
long o = ul2Data(buf, l.first, byteOrder);
size_t ur2Data(byte* buf, URational l, ByteOrder byteOrder) {
size_t o = ul2Data(buf, l.first, byteOrder);
o += ul2Data(buf + o, l.second, byteOrder);
return o;
}

long s2Data(byte* buf, int16_t s, ByteOrder byteOrder) {
size_t s2Data(byte* buf, int16_t s, ByteOrder byteOrder) {
if (byteOrder == littleEndian) {
buf[0] = static_cast<byte>(s & 0x00ffU);
buf[1] = static_cast<byte>((s & 0xff00U) >> 8);
Expand All @@ -389,7 +389,7 @@ long s2Data(byte* buf, int16_t s, ByteOrder byteOrder) {
return 2;
}

long l2Data(byte* buf, int32_t l, ByteOrder byteOrder) {
size_t l2Data(byte* buf, int32_t l, ByteOrder byteOrder) {
if (byteOrder == littleEndian) {
buf[0] = static_cast<byte>(l & 0x000000ffU);
buf[1] = static_cast<byte>((l & 0x0000ff00U) >> 8);
Expand All @@ -404,13 +404,13 @@ long l2Data(byte* buf, int32_t l, ByteOrder byteOrder) {
return 4;
}

long r2Data(byte* buf, Rational l, ByteOrder byteOrder) {
long o = l2Data(buf, l.first, byteOrder);
size_t r2Data(byte* buf, Rational l, ByteOrder byteOrder) {
size_t o = l2Data(buf, l.first, byteOrder);
o += l2Data(buf + o, l.second, byteOrder);
return o;
}

long f2Data(byte* buf, float f, ByteOrder byteOrder) {
size_t f2Data(byte* buf, float f, ByteOrder byteOrder) {
// This algorithm assumes that the internal representation of the float
// type is the 4-byte IEEE 754 binary32 format, which is common but not
// required by the C++ standard.
Expand All @@ -422,7 +422,7 @@ long f2Data(byte* buf, float f, ByteOrder byteOrder) {
return ul2Data(buf, u.ul_, byteOrder);
}

long d2Data(byte* buf, double d, ByteOrder byteOrder) {
size_t d2Data(byte* buf, double d, ByteOrder byteOrder) {
// This algorithm assumes that the internal representation of the double
// type is the 8-byte IEEE 754 binary64 format, which is common but not
// required by the C++ standard.
Expand Down

0 comments on commit 4410f46

Please sign in to comment.