minor fixes

remove unreachable code
add parameter checks to mbus_data_bcd_encode
init time structure in mbus_data_tm_decode as possible
mark falltrough for splint
remove unused variable val
fix removed realloc
This commit is contained in:
Stefan Wahren 2013-05-04 22:43:23 +02:00
parent ee209023b8
commit c59e763a84
2 changed files with 26 additions and 23 deletions

View File

@ -768,7 +768,6 @@ int mbus_fixed_normalize(int medium_unit, long medium_value, char **unit_out, do
exponent = 0.0;
*value_out = 0.0;
return -1;
break;
}
return -2;

View File

@ -451,15 +451,15 @@ mbus_data_bcd_encode(unsigned char *bcd_data, size_t bcd_data_size, int value)
int v0, v1, v2, x1, x2;
size_t i;
if (bcd_data && bcd_data_size && (value >= 0))
{
v2 = value;
if (bcd_data)
{
for (i = 0; i < bcd_data_size; i++)
{
v0 = v2;
v1 = (int)(v0 / 10.0);
v2 = (int)(v1 / 10.0);
v1 = (int)(v0 / 10);
v2 = (int)(v1 / 10);
x1 = v0 - v1 * 10;
x2 = v1 - v2 * 10;
@ -689,16 +689,23 @@ mbus_data_bin_decode(unsigned char *dst, const unsigned char *src, size_t len, s
void
mbus_data_tm_decode(struct tm *t, unsigned char *t_data, size_t t_data_size)
{
if (t && t_data)
if (t == NULL)
{
return;
}
t->tm_sec = 0;
t->tm_min = 0;
t->tm_hour = 0;
t->tm_mday = 0;
t->tm_mon = 0;
t->tm_year = 0;
t->tm_wday = 0;
t->tm_yday = 0;
t->tm_isdst = 0;
if (t_data)
{
if (t_data_size == 4) // Type F = Compound CP32: Date and Time
{
if ((t_data[0] & 0x80) == 0) // Time valid ?
@ -2363,7 +2370,7 @@ mbus_data_record_decode(mbus_data_record *record)
mbus_data_str_decode(buff, record->data, record->data_len);
break;
}
/* FALLTHROUGH */
/*@fallthrough@*/
default:
@ -2878,12 +2885,8 @@ mbus_frame_data_parse(mbus_frame *frame, mbus_frame_data *data)
return -1;
}
}
else
{
snprintf(error_str, sizeof(error_str), "Wrong direction in frame (master to slave)");
return -1;
}
snprintf(error_str, sizeof(error_str), "Wrong direction in frame (master to slave)");
return -1;
}
@ -3461,7 +3464,6 @@ mbus_data_variable_record_xml(mbus_data_record *record, int record_cnt, int fram
size_t len = 0;
struct tm * timeinfo;
char timestamp[21];
int val;
if (record)
{
@ -3804,6 +3806,8 @@ mbus_frame_xml(mbus_frame *frame)
if ((buff_size - len) < 1024)
{
buff_size *= 2;
new_buff = (char*) realloc(buff,buff_size);
if (new_buff == NULL)
{
free(buff);