Uemis patches
Miika Turkia
miika.turkia at gmail.com
Mon Sep 7 07:14:42 PDT 2015
On Mon, Sep 7, 2015 at 4:45 PM, Guido Lerch <guido.lerch at gmail.com> wrote:
> All,
>
> Attached two Uemis patches after the 10 Dirk applied for me.
Hello and thanks for the patches. I have some suggestions for a little
rework on them. First of all, you should configure your editor to use
tab for indentation (no spaces).
+ /* quickhack and workaround to capture the original dive_no
+ * i am doing this so I dont have to change the original design
+ * but when parsing a dive we never parse the dive number because
+ * at the time it's being read the *dive varible is not set because
+ * the dive_no tag comes before the object_id in the uemis ans file
+ */
+ char *dive_no_buf = strdup(inbuf);
+ char *dive_no_ptr = strstr(dive_no_buf, "dive_no{int{") + 12;
You should ensure the strstr returns a valid pointer and not null. If
null is returned, the input file is not valid and you should take that
into account. (I have implemented way too many bugs myself when
importing data with no proper validation - the input just isn't always
according to the spec.)
+ char *dive_no_end = strstr(dive_no_ptr, "{");
Are you really looking for { and not closing char? And you should
again make sure the return value is not null. I believe strchr would
be faster when you are searching for one character only.
+ *dive_no_end = 0;
You might segm fault if you got null in the previous search.
+ strcpy(dive_no, dive_no_ptr);
I suggest you use strncpy instead of strcpy to avoid buffer overflows.
(Note that strncpy does not null terminate if the input length is n or
more.)
miika
More information about the subsurface
mailing list