Skip to content
Snippets Groups Projects
Commit 5b039e84 authored by Kristof Szabados's avatar Kristof Szabados
Browse files

checked conversion to stay within limits.


Signed-off-by: default avatarKristof Szabados <Kristof.Szabados@ericsson.com>
parent 8478ba91
No related branches found
No related tags found
No related merge requests found
...@@ -66,10 +66,10 @@ void Quad::set(unsigned char group, unsigned char plane, unsigned char row, ...@@ -66,10 +66,10 @@ void Quad::set(unsigned char group, unsigned char plane, unsigned char row,
} }
void Quad::set_hexrepr(const char* hex_repr) { void Quad::set_hexrepr(const char* hex_repr) {
u.comp.group = ((hex_repr[0] - 'A') << 4) + (hex_repr[1] - 'A'); u.comp.group = (unsigned char)(((hex_repr[0] - 'A') << 4) + (hex_repr[1] - 'A'));
u.comp.plane = ((hex_repr[2] - 'A') << 4) + (hex_repr[3] - 'A'); u.comp.plane = (unsigned char)(((hex_repr[2] - 'A') << 4) + (hex_repr[3] - 'A'));
u.comp.row = ((hex_repr[4] - 'A') << 4) + (hex_repr[5] - 'A'); u.comp.row = (unsigned char)(((hex_repr[4] - 'A') << 4) + (hex_repr[5] - 'A'));
u.comp.cell = ((hex_repr[6] - 'A') << 4) + (hex_repr[7] - 'A'); u.comp.cell = (unsigned char)(((hex_repr[6] - 'A') << 4) + (hex_repr[7] - 'A'));
} }
const Quad Quad::operator-(const Quad& rhs) const { const Quad Quad::operator-(const Quad& rhs) const {
...@@ -133,21 +133,21 @@ char* Quad::get_hexrepr(unsigned int value) { ...@@ -133,21 +133,21 @@ char* Quad::get_hexrepr(unsigned int value) {
} }
void Quad::get_hexrepr(const Quad& q, char* const str) { void Quad::get_hexrepr(const Quad& q, char* const str) {
str[0] = 'A' + (q.u.comp.group >> 4); // high end str[0] = (char)('A' + (q.u.comp.group >> 4)); // high end
str[1] = 'A' + (q.u.comp.group & 15); str[1] = (char)('A' + (q.u.comp.group & 15));
str[2] = 'A' + (q.u.comp.plane >> 4); str[2] = (char)('A' + (q.u.comp.plane >> 4));
str[3] = 'A' + (q.u.comp.plane & 15); str[3] = (char)('A' + (q.u.comp.plane & 15));
str[4] = 'A' + (q.u.comp.row >> 4); str[4] = (char)('A' + (q.u.comp.row >> 4));
str[5] = 'A' + (q.u.comp.row & 15); str[5] = (char)('A' + (q.u.comp.row & 15));
str[6] = 'A' + (q.u.comp.cell >> 4); str[6] = (char)('A' + (q.u.comp.cell >> 4));
str[7] = 'A' + (q.u.comp.cell & 15); // low end str[7] = (char)('A' + (q.u.comp.cell & 15)); // low end
} }
char* Quad::char_hexrepr(unsigned char c) { char* Quad::char_hexrepr(unsigned char c) {
char hex[3]; char hex[3];
hex[2] = '\0'; hex[2] = '\0';
hex[1] = (c & 15) + 'A'; hex[1] = (char)((c & 15) + 'A');
hex[0] = (c >> 4) + 'A'; hex[0] = (char)((c >> 4) + 'A');
return mcopystr(hex); return mcopystr(hex);
} }
...@@ -235,7 +235,7 @@ char* QuadInterval::generate_posix() { ...@@ -235,7 +235,7 @@ char* QuadInterval::generate_posix() {
Free(str); Free(str);
q1.set(j, 0); q1.set(j, 0);
if (j > 0 && q1[j-1] < 255) if (j > 0 && q1[j-1] < 255)
q1.set(j - 1, q1[j-1] + 1); q1.set(j - 1, (unsigned char)(q1[j-1] + 1));
for (k = j + 1; k < 4; k++) { for (k = j + 1; k < 4; k++) {
res = mputprintf(res, "%s", res = mputprintf(res, "%s",
str = generate_hex_interval(0, 255)); str = generate_hex_interval(0, 255));
...@@ -251,7 +251,7 @@ char* QuadInterval::generate_posix() { ...@@ -251,7 +251,7 @@ char* QuadInterval::generate_posix() {
res = mputstr(res, str = Quad::char_hexrepr(lower[j])); res = mputstr(res, str = Quad::char_hexrepr(lower[j]));
Free(str); Free(str);
} }
str = generate_hex_interval(lower[c] + 1, str = generate_hex_interval((unsigned char)(lower[c] + 1),
(unsigned char)(lower[c] + diff[c] - 1)); (unsigned char)(lower[c] + diff[c] - 1));
res = mputprintf(res, "%s", str); res = mputprintf(res, "%s", str);
Free(str); Free(str);
...@@ -274,7 +274,7 @@ char* QuadInterval::generate_posix() { ...@@ -274,7 +274,7 @@ char* QuadInterval::generate_posix() {
} }
c++; c++;
if (c < 3) if (c < 3)
q2.set(c, upper[c] - 1); q2.set(c, (unsigned char)(upper[c] - 1));
res = mputstr(res, str = generate_hex_interval(q1[c], q2[c])); res = mputstr(res, str = generate_hex_interval(q1[c], q2[c]));
Free(str); Free(str);
for (j = c + 1; j < 4; j++) { for (j = c + 1; j < 4; j++) {
......
...@@ -936,8 +936,8 @@ size_t mstrlen(const expstring_t str) ...@@ -936,8 +936,8 @@ size_t mstrlen(const expstring_t str)
} else return 0; } else return 0;
} }
char * buildstr(int b) { char * buildstr(unsigned int b) {
if (b < 0 || b > 99) return NULL; /* invalid */ if (b > 99) return NULL; /* invalid */
if (b == 99) return memptystr(); /* empty string for full version */ if (b == 99) return memptystr(); /* empty string for full version */
return mprintf("%02d", b); return mprintf("%02d", b);
} }
...@@ -282,13 +282,14 @@ extern "C" { ...@@ -282,13 +282,14 @@ extern "C" {
* @return a string which must be Free()-d by the caller * @return a string which must be Free()-d by the caller
* @pre b > 0 and b <= 99, or else NULL is returned * @pre b > 0 and b <= 99, or else NULL is returned
*/ */
char * buildstr(int b); char * buildstr(unsigned int b);
#ifdef __cplusplus #ifdef __cplusplus
/** Convert a patch level to the "Ericsson letter" */ /** Convert a patch level to the "Ericsson letter" */
inline char eri(unsigned int p) { /* p stands for patch level */ inline char eri(unsigned int p) { /* p stands for patch level */
char i = (char)('A' + p); /* i stands for "if only it was that simple" */ char i = (char)('A' + p); /* i stands for "if only it was that simple" */
return i + (i >= 'I') + 4 * (i >= 'N') + (i >= 'R'); const int result = i + (i >= 'I') + 4 * (i >= 'N') + (i >= 'R');
return (char)result; /*check: does not overflow*/
} }
} /* extern "C" */ } /* extern "C" */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment