Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re-align COBOL_TYPE_UNSIGNED_BINARY code to use switch #136

Closed
GitMensch opened this issue Dec 30, 2022 · 1 comment
Closed

re-align COBOL_TYPE_UNSIGNED_BINARY code to use switch #136

GitMensch opened this issue Dec 30, 2022 · 1 comment
Labels
Milestone

Comments

@GitMensch
Copy link
Contributor

I'd have sent in a PR, but I'm not sure about the not-yet-checked-in changes with the dynamic memory changing the related code, so here's the suggestion to change those lines:

case COBOL_TYPE_UNSIGNED_BINARY:
if (this->length == 1) { // 1 byte
uint8_t n8 = *((uint8_t*)addr);
snprintf((char*)realdata, length, "%d", n8);
}
else {
if (this->length == 2) { // 1 byte
uint8_t n8 = *((uint8_t*)addr);
snprintf((char*)realdata, length, "%d", n8);
}
else {
if (this->length == 3 || this->length == 4) { // 2 bytes
uint16_t n16 = *((uint16_t*)addr);
n16 = COB_BSWAP_16(n16);
snprintf((char*)realdata, length, "%d", n16);
}
else {
if (this->length >= 5 || this->length <= 9) { // 4 bytes
uint32_t n32 = *((uint32_t*)addr);
n32 = COB_BSWAP_32(n32);
snprintf((char*)realdata, length, "%d", n32);
}
else {
if (this->length >= 10 || this->length <= 18) { // 8 bytes
uint64_t n64 = *((uint64_t*)addr);
n64 = COB_BSWAP_64(n64);
snprintf((char*)realdata, length, "%d", n64);
}
else {
// Should never happen - TODO: log fatal and abort
}
}
}
}
}

(and similar) to use switch (this->length) instead of nested if/else.

I may send in a PR for that when wanted, too.

@mridoni
Copy link
Owner

mridoni commented Dec 30, 2022

This is undergoing a massive overhaul due to #124, so a PR would be probably wasted, but I am scheduling this for v1.0.20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants