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
input: add import module for tektronix isf file format #186
Changes from 4 commits
f5ab583
741a37b
166b486
e36ebb0
4f87b65
2825e37
0f1e957
60b2ac0
2407599
d8b8f9c
332fafd
482955d
94e475a
3704fc1
8b9d1e1
2081200
228a5ee
17b954f
e9f509b
af06f48
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,8 +177,14 @@ static char *find_data_section(GString *buf) | |
if (offset >= buf->len) | ||
return NULL; | ||
|
||
/* Curve metadata length is an ASCII byte, hence -48. */ | ||
metadata_length = (size_t) *data_ptr - 48; | ||
/* | ||
* Curve metadata length is encoded as an ASCII | ||
* digit '0' to '9', hence -48. | ||
*/ | ||
metadata_length = (size_t) *data_ptr; | ||
if (metadata_length < 48 || metadata_length > 57) | ||
return NULL; | ||
metadata_length -= 48; | ||
data_ptr += 1 + metadata_length; | ||
offset = (size_t) (data_ptr - buf->str); | ||
|
||
|
@@ -236,7 +242,7 @@ static int find_encoding(const char *buf, size_t buflen) | |
|
||
find_string_value(buf, buflen, value, MAX_ENCODING_STRING_SIZE); | ||
|
||
/* "BIN" and "BINARY" are accepted as suggested in a pull request comment. */ | ||
/* "BIN" and "BINARY" are accepted. */ | ||
if (strcmp(value, "BINARY") != 0 && strcmp(value, "BIN") != 0) { | ||
sr_err("Only binary encoding supported."); | ||
return SR_ERR_NA; | ||
|
@@ -468,22 +474,21 @@ static int format_match(GHashTable *metadata, unsigned int *confidence) | |
char *fn; | ||
size_t fn_len; | ||
|
||
/* If the extension is '.isf', it is likely the format matches. */ | ||
fn = g_hash_table_lookup(metadata, GINT_TO_POINTER(SR_INPUT_META_FILENAME)); | ||
if (fn != NULL && (fn_len = strlen(fn)) >= strlen(default_extension)) { | ||
if (strcmp(fn + fn_len - strlen(default_extension), default_extension) == 0) { | ||
*confidence = 10; | ||
return SR_OK; | ||
} | ||
} | ||
|
||
buf = g_hash_table_lookup(metadata, GINT_TO_POINTER(SR_INPUT_META_HEADER)); | ||
/* Check if the header contains NR_PT item. */ | ||
if (buf == NULL || g_strstr_len(buf->str, buf->len, nr_pt) == NULL) | ||
return SR_ERR; | ||
|
||
/* The header contains NR_PT item, the confidence is high. */ | ||
*confidence = 50; | ||
|
||
/* Increase the confidence if the extension is '.isf'. */ | ||
fn = g_hash_table_lookup(metadata, GINT_TO_POINTER(SR_INPUT_META_FILENAME)); | ||
if (fn != NULL && (fn_len = strlen(fn)) >= strlen(default_extension)) { | ||
if (g_ascii_strcasecmp(fn + fn_len - strlen(default_extension), default_extension) == 0) { | ||
*confidence += 10; | ||
} | ||
} | ||
return SR_OK; | ||
} | ||
|
||
|
@@ -520,7 +525,8 @@ static float read_int_sample(struct sr_input *in, size_t offset) | |
inc = in->priv; | ||
bytnr = inc->bytnr; | ||
|
||
/* Value bytnr is checked in function "receive". */ | ||
if (bytnr > MAX_INT_BYTNR) | ||
return 0; | ||
memcpy(data, in->buf->str + offset, bytnr); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bounds check on bytnr before memcpy ? not sure if that's what you mean in the comment on the previous line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bounds checking on bytnr is now performed. |
||
value = 0; | ||
if (inc->byte_order == MSB) { | ||
|
@@ -559,7 +565,8 @@ static float read_unsigned_int_sample(struct sr_input *in, size_t offset) | |
|
||
inc = in->priv; | ||
|
||
/* Value bytnr is checked in function "receive". */ | ||
if (inc->bytnr > MAX_INT_BYTNR) | ||
return 0; | ||
memcpy(data, in->buf->str + offset, inc->bytnr); | ||
if (inc->byte_order == MSB) { | ||
for (i = 0; i < (int) inc->bytnr; ++i) { | ||
|
@@ -593,7 +600,8 @@ static float read_float_sample(struct sr_input *in, size_t offset) | |
bytnr = inc->bytnr; | ||
fp.i = 0; | ||
|
||
/* Value bytnr is checked in function "receive". */ | ||
if (bytnr > FLOAT_BYTNR) | ||
return 0; | ||
memcpy(data, in->buf->str + offset, bytnr); | ||
|
||
if (inc->byte_order == MSB) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I didn't catch this last time but you have an assignment inside a conditional, which should be split (I think that is now mentioned in the HACKING doc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.