Skip to content

Commit

Permalink
Fixed a possible size end-ordering error.
Browse files Browse the repository at this point in the history
Merge pull request #46 from ax-6/main
  • Loading branch information
ax-6 authored Sep 26, 2024
2 parents 0cf53a9 + 1337014 commit bc2de4a
Showing 1 changed file with 32 additions and 20 deletions.
52 changes: 32 additions & 20 deletions prototype/prototype.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,91 +323,103 @@ void SetByteData(size_t index, int8_t value) {
}

void SetIntData(size_t index, int value) {
value = is_big_endian ? value : SwapInt(value);
switch (GetType(memory, index)) {
case 0x01:
*(int8_t*)((uintptr_t)memory->data + index) = value;
break;
case 0x02:
*(int*)((uintptr_t)memory->data + index) = value;
*(int*)((uintptr_t)memory->data + index) =
is_big_endian ? value : SwapInt(value);
break;
case 0x03:
*(long*)((uintptr_t)memory->data + index) = value;
*(long*)((uintptr_t)memory->data + index) =
is_big_endian ? value : SwapLong(value);
break;
case 0x04:
*(float*)((uintptr_t)memory->data + index) = value;
*(float*)((uintptr_t)memory->data + index) =
is_big_endian ? value : SwapFloat(value);
break;
case 0x05:
*(double*)((uintptr_t)memory->data + index) = value;
*(double*)((uintptr_t)memory->data + index) =
is_big_endian ? value : SwapDouble(value);
break;
default:
break;
}
}

void SetLongData(size_t index, long value) {
value = is_big_endian ? value : SwapLong(value);
switch (GetType(memory, index)) {
case 0x01:
*(int8_t*)((uintptr_t)memory->data + index) = value;
break;
case 0x02:
*(int*)((uintptr_t)memory->data + index) = value;
*(int*)((uintptr_t)memory->data + index) =
is_big_endian ? value : SwapInt(value);
break;
case 0x03:
*(long*)((uintptr_t)memory->data + index) = value;
*(long*)((uintptr_t)memory->data + index) =
is_big_endian ? value : SwapLong(value);
break;
case 0x04:
*(float*)((uintptr_t)memory->data + index) = value;
*(float*)((uintptr_t)memory->data + index) =
is_big_endian ? value : SwapFloat(value);
break;
case 0x05:
*(double*)((uintptr_t)memory->data + index) = value;
*(double*)((uintptr_t)memory->data + index) =
is_big_endian ? value : SwapDouble(value);
break;
default:
break;
}
}

void SetFloatData(size_t index, float value) {
value = is_big_endian ? value : SwapFloat(value);
switch (GetType(memory, index)) {
case 0x01:
*(int8_t*)((uintptr_t)memory->data + index) = value;
break;
case 0x02:
*(int*)((uintptr_t)memory->data + index) = value;
*(int*)((uintptr_t)memory->data + index) =
is_big_endian ? value : SwapInt(value);
break;
case 0x03:
*(long*)((uintptr_t)memory->data + index) = value;
*(long*)((uintptr_t)memory->data + index) =
is_big_endian ? value : SwapLong(value);
break;
case 0x04:
*(float*)((uintptr_t)memory->data + index) = value;
*(float*)((uintptr_t)memory->data + index) =
is_big_endian ? value : SwapFloat(value);
break;
case 0x05:
*(double*)((uintptr_t)memory->data + index) = value;
*(double*)((uintptr_t)memory->data + index) =
is_big_endian ? value : SwapDouble(value);
break;
default:
break;
}
}

void SetDoubleData(size_t index, double value) {
value = is_big_endian ? value : SwapDouble(value);
switch (GetType(memory, index)) {
case 0x01:
*(int8_t*)((uintptr_t)memory->data + index) = value;
break;
case 0x02:
*(int*)((uintptr_t)memory->data + index) = value;
*(int*)((uintptr_t)memory->data + index) =
is_big_endian ? value : SwapInt(value);
break;
case 0x03:
*(long*)((uintptr_t)memory->data + index) = value;
*(long*)((uintptr_t)memory->data + index) =
is_big_endian ? value : SwapLong(value);
break;
case 0x04:
*(float*)((uintptr_t)memory->data + index) = value;
*(float*)((uintptr_t)memory->data + index) =
is_big_endian ? value : SwapFloat(value);
break;
case 0x05:
*(double*)((uintptr_t)memory->data + index) = value;
*(double*)((uintptr_t)memory->data + index) =
is_big_endian ? value : SwapDouble(value);
break;
default:
break;
Expand Down

0 comments on commit bc2de4a

Please sign in to comment.