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

kernel/hal: hal_i2s doesn't display number when zero == 0 and i == 0 #555

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions hal/armv7a/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,14 @@ unsigned long hal_i2s(const char *prefix, char *s, unsigned long i, unsigned cha
m = hal_strlen(prefix);
hal_memcpy(s, prefix, m);

for (k = m, l = (unsigned long)-1; l; i /= b, l /= b) {
if (!zero && !i)
if ((zero == 0) && (i == 0)) {
s[m++] = '0';
}

for (k = m, l = (unsigned long)-1; l != 0; i /= b, l /= b) {
if ((zero == 0) && (i == 0)) {
break;
}
s[k++] = digits[i % b];
}

Expand Down
9 changes: 7 additions & 2 deletions hal/armv7m/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,14 @@ unsigned long hal_i2s(const char *prefix, char *s, unsigned long i, unsigned cha
m = hal_strlen(prefix);
hal_memcpy(s, prefix, m);

for (k = m, l = (unsigned long)-1; l; i /= b, l /= b) {
if (!zero && !i)
if ((zero == 0) && (i == 0)) {
s[m++] = '0';
}

for (k = m, l = (unsigned long)-1; l != 0; i /= b, l /= b) {
if ((zero == 0) && (i == 0)) {
break;
}
s[k++] = digits[i % b];
}

Expand Down
8 changes: 6 additions & 2 deletions hal/armv8m/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,12 @@ unsigned long hal_i2s(const char *prefix, char *s, unsigned long i, unsigned cha
m = hal_strlen(prefix);
hal_memcpy(s, prefix, m);

for (k = m, l = (unsigned long)-1; l; i /= b, l /= b) {
if (!zero && !i) {
if ((zero == 0) && (i == 0)) {
s[m++] = '0';
}

for (k = m, l = (unsigned long)-1; l != 0; i /= b, l /= b) {
if ((zero == 0) && (i == 0)) {
break;
}
s[k++] = digits[i % b];
Expand Down
50 changes: 32 additions & 18 deletions hal/ia32/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ void hal_memcpy(void *dst, const void *src, size_t l)

int hal_memcmp(const void *ptr1, const void *ptr2, size_t num)
{
int i;
size_t i;

for (i = 0; i < num; ++i) {
if (((const u8 *)ptr1)[i] < ((const u8 *)ptr2)[i])
if (((const u8 *)ptr1)[i] < ((const u8 *)ptr2)[i]) {
return -1;
else if (((const u8 *)ptr1)[i] > ((const u8 *)ptr2)[i])
}
else if (((const u8 *)ptr1)[i] > ((const u8 *)ptr2)[i]) {
return 1;
}
}

return 0;
Expand Down Expand Up @@ -85,10 +87,11 @@ void hal_memset(void *dst, int v, size_t l)

size_t hal_strlen(const char *s)
{
unsigned int k;
size_t k;

for (k = 0; *s; s++, k++)
for (k = 0; *s; s++, k++) {
;
}

return k;
}
Expand All @@ -99,18 +102,21 @@ int hal_strcmp(const char *s1, const char *s2)
const unsigned char *us1 = (const unsigned char *)s1;
const unsigned char *us2 = (const unsigned char *)s2;
const unsigned char *p;
unsigned int k;
size_t k;

for (p = us1, k = 0; *p; p++, k++) {

if (*p < *(us2 + k))
if (*p < *(us2 + k)) {
return -1;
else if (*p > *(us2 + k))
}
else if (*p > *(us2 + k)) {
return 1;
}
}

if (*p != *(us2 + k))
if (*p != *(us2 + k)) {
return -1;
}

return 0;
}
Expand All @@ -120,21 +126,23 @@ int hal_strncmp(const char *s1, const char *s2, size_t count)
{
const unsigned char *us1 = (const unsigned char *)s1;
const unsigned char *us2 = (const unsigned char *)s2;
unsigned int k;
size_t k;

for (k = 0; k < count && *us1 && *us2 && (*us1 == *us2); ++k, ++us1, ++us2)
for (k = 0; (k < count) && (*us1 != 0) && (*us2 != 0) && (*us1 == *us2); ++k, ++us1, ++us2) {
;
}

if (k == count || (!*us1 && !*us2))
if ((k == count) || ((*us1 == 0) && (*us2 == 0))) {
return 0;
}

return (*us1 < *us2) ? -k - 1 : k + 1;
}


char *hal_strcpy(char *dest, const char *src)
{
int i = 0;
size_t i = 0;

do {
dest[i] = src[i];
Expand All @@ -146,15 +154,16 @@ char *hal_strcpy(char *dest, const char *src)

char *hal_strncpy(char *dest, const char *src, size_t n)
{
int i = 0;
size_t i = 0;

if (n == 0)
if (n == 0) {
return dest;
}

do {
dest[i] = src[i];
i++;
} while (i < n && src[i - 1] != '\0');
} while ((i < n) && (src[i - 1] != '\0'));

return dest;
}
Expand All @@ -169,9 +178,14 @@ unsigned long hal_i2s(const char *prefix, char *s, unsigned long i, unsigned cha
m = hal_strlen(prefix);
hal_memcpy(s, prefix, m);

for (k = m, l = (unsigned long)-1; l; i /= b, l /= b) {
if (!zero && !i)
if ((zero == 0) && (i == 0)) {
s[m++] = '0';
}

for (k = m, l = (unsigned long)-1; l != 0; i /= b, l /= b) {
if ((zero == 0) && (i == 0)) {
break;
}
s[k++] = digits[i % b];
}

Expand Down
47 changes: 31 additions & 16 deletions hal/riscv64/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@

int hal_memcmp(const void *ptr1, const void *ptr2, size_t num)
{
int i;
size_t i;

for (i = 0; i < num; ++i) {
if (((const u8 *)ptr1)[i] < ((const u8 *)ptr2)[i])
if (((const u8 *)ptr1)[i] < ((const u8 *)ptr2)[i]) {
return -1;
else if (((const u8 *)ptr1)[i] > ((const u8 *)ptr2)[i])
}
else if (((const u8 *)ptr1)[i] > ((const u8 *)ptr2)[i]) {
return 1;
}
}

return 0;
Expand All @@ -36,8 +38,9 @@ size_t hal_strlen(const char *s)
{
size_t k;

for (k = 0; *s; s++, k++)
for (k = 0; *s; s++, k++) {
;
}

return k;
}
Expand All @@ -48,18 +51,21 @@ int hal_strcmp(const char *s1, const char *s2)
const unsigned char *us1 = (const unsigned char *)s1;
const unsigned char *us2 = (const unsigned char *)s2;
const unsigned char *p;
unsigned int k;
size_t k;

for (p = us1, k = 0; *p; p++, k++) {

if (*p < *(us2 + k))
if (*p < *(us2 + k)) {
return -1;
else if (*p > *(us2 + k))
}
else if (*p > *(us2 + k)) {
return 1;
}
}

if (*p != *(us2 + k))
if (*p != *(us2 + k)) {
return -1;
}

return 0;
}
Expand All @@ -71,18 +77,21 @@ int hal_strncmp(const char *s1, const char *s2, size_t count)
const unsigned char *us2 = (const unsigned char *)s2;
size_t k;

for (k = 0; k < count && *us1 && *us2 && (*us1 == *us2); ++k, ++us1, ++us2);
for (k = 0; (k < count) && (*us1 != 0) && (*us2 != 0) && (*us1 == *us2); ++k, ++us1, ++us2) {
;
}

if (k == count || (!*us1 && !*us2))
if ((k == count) || ((*us1 == 0) && (*us2 == 0))) {
return 0;
}

return (*us1 < *us2) ? -k - 1 : k + 1;
}


char *hal_strcpy(char *dest, const char *src)
{
int i = 0;
size_t i = 0;

do {
dest[i] = src[i];
Expand All @@ -94,15 +103,16 @@ char *hal_strcpy(char *dest, const char *src)

char *hal_strncpy(char *dest, const char *src, size_t n)
{
int i = 0;
size_t i = 0;

if (n == 0)
if (n == 0) {
return dest;
}

do {
dest[i] = src[i];
i++;
} while (i < n && src[i - 1] != '\0');
} while ((i < n) && (src[i - 1] != '\0'));

return dest;
}
Expand All @@ -117,9 +127,14 @@ unsigned long hal_i2s(const char *prefix, char *s, unsigned long i, unsigned cha
m = hal_strlen(prefix);
hal_memcpy(s, prefix, m);

for (k = m, l = (unsigned long)-1; l; i /= b, l /= b) {
if (!zero && !i)
if ((zero == 0) && (i == 0)) {
s[m++] = '0';
}

for (k = m, l = (unsigned long)-1; l != 0; i /= b, l /= b) {
if ((zero == 0) && (i == 0)) {
break;
}
s[k++] = digits[i % b];
}

Expand Down
11 changes: 8 additions & 3 deletions hal/sparcv8leon3/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,19 @@ unsigned long hal_i2s(const char *prefix, char *s, unsigned long i, unsigned cha
{
static const char digits[] = "0123456789abcdef";
char c;
unsigned int l, k, m;
unsigned long l, k, m;

m = hal_strlen(prefix);
hal_memcpy(s, prefix, m);

for (k = m, l = (unsigned int)-1; l; i /= b, l /= b) {
if (!zero && !i)
if ((zero == 0) && (i == 0)) {
s[m++] = '0';
}

for (k = m, l = (unsigned long)-1; l != 0; i /= b, l /= b) {
if ((zero == 0) && (i == 0)) {
break;
}
s[k++] = digits[i % b];
}

Expand Down
Loading