Change all length fields to size_t #12

Closed
opened 2020-02-03 17:34:26 +01:00 by mohr · 9 comments
Owner
No description provided.
mohr self-assigned this 2020-02-03 17:34:26 +01:00
mohr added the
feature
label 2020-02-03 17:34:26 +01:00
Owner

Started replacement in DHB rework.

Started replacement in DHB rework.
Owner

Replaced uint32_t/int32_t for all SerializeIF calls (ssize_t for int32_t). There are a lot of functions implementing SerializeIF. merge request coming soon

Replaced uint32_t/int32_t for all SerializeIF calls (ssize_t for int32_t). There are a lot of functions implementing SerializeIF. merge request coming soon
Owner

Is size_t intended to be used in SerializeIF? And how to handle the signed size?( ssize_t)

Possible C++11 solution:

#ifndef ssize_t
typedef std::make_signed<std::size_t>::type ssize_t;
#endif
Is size_t intended to be used in SerializeIF? And how to handle the signed size?( ssize_t) Possible C++11 solution: ```cpp #ifndef ssize_t typedef std::make_signed<std::size_t>::type ssize_t; #endif ```
Owner

After talking with Steffen: Maybe also use size_t for deSerialize and detect overflows by
using

if((*size - sizeToDeserialize) >= *size) {
   return SOME_ERROR_VALUE
}

to check for overflows?
This has potential to create evil bugs if it is not done properly for alle deSerialize calls/overrides

After talking with Steffen: Maybe also use size_t for deSerialize and detect overflows by using ```cpp if((*size - sizeToDeserialize) >= *size) { return SOME_ERROR_VALUE } ``` to check for overflows? This has potential to create evil bugs if it is not done properly for alle deSerialize calls/overrides
Author
Owner

#35 started work on this

#35 started work on this
Author
Owner

Is size_t intended to be used in SerializeIF? And how to handle the signed size?( ssize_t)

Possible C++11 solution:

#ifndef ssize_t
typedef std::make_signed<std::size_t>::type ssize_t;
#endif

No need to typedef ssize_t, it is in stdio.h sys/types.h and unistd.h, one of which should be available in a typical installation.

> Is size_t intended to be used in SerializeIF? And how to handle the signed size?( ssize_t) > > Possible C++11 solution: > > ```cpp > #ifndef ssize_t > typedef std::make_signed<std::size_t>::type ssize_t; > #endif > ``` No need to typedef ssize_t, it is in stdio.h sys/types.h and unistd.h, one of which should be available in a typical installation.
mohr added the
API Change
label 2020-04-17 18:02:48 +02:00
Owner

We can just use size_t like discussed for deSerialize.
Example AutoSerializeAdapter:

ReturnValue_t deSerialize(T* object, const uint8_t** buffer, size_t* size,
			bool bigEndian) {
		T tmp;
		if (*size >= sizeof(T)) {
			*size -= sizeof(T);
			memcpy(&tmp, *buffer, sizeof(T));
			if (bigEndian) {
				*object = EndianSwapper::swap<T>(tmp);
			} else {
				*object = tmp;
			}
			*buffer += sizeof(T);
			return HasReturnvaluesIF::RETURN_OK;
		} else {
			return SerializeIF::STREAM_TOO_SHORT;
		}
	} 
We can just use size_t like discussed for deSerialize. Example AutoSerializeAdapter: ```cpp ReturnValue_t deSerialize(T* object, const uint8_t** buffer, size_t* size, bool bigEndian) { T tmp; if (*size >= sizeof(T)) { *size -= sizeof(T); memcpy(&tmp, *buffer, sizeof(T)); if (bigEndian) { *object = EndianSwapper::swap<T>(tmp); } else { *object = tmp; } *buffer += sizeof(T); return HasReturnvaluesIF::RETURN_OK; } else { return SerializeIF::STREAM_TOO_SHORT; } } ```
Owner

What's the state of this issue?

What's the state of this issue?
Owner

Most usages are fixed by now. I think we can open issues/pull request for single fixes, because they should be rare now.

Most usages are fixed by now. I think we can open issues/pull request for single fixes, because they should be rare now.
gaisser added this to the Release Apollo-Sojus-Test-Project (ASTP) 0.0.1 milestone 2020-12-03 18:38:01 +01:00
Sign in to join this conversation.
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: fsfw/fsfw#12
No description provided.