Don't ignore return value of write. This fix following build error on
Ubuntu:
tools/seq2bseq.c: In function ‘convert_line’:
tools/seq2bseq.c:52:8: error: ignoring return value of ‘write’,
declared with attribute warn_unused_result [-Werror=unused-result]
write(fd, &val, 1);
---
tools/seq2bseq.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/tools/seq2bseq.c b/tools/seq2bseq.c
index 6d70777..9797f5f 100644
--- a/tools/seq2bseq.c
+++ b/tools/seq2bseq.c
@@ -31,16 +31,17 @@
#include <string.h>
#include <stdlib.h>
#include <getopt.h>
+#include <errno.h>
#include <sys/stat.h>
-static void convert_line(int fd, const char *line)
+static int convert_line(int fd, const char *line)
{
const char *ptr = line;
char str[3];
unsigned char val;
if (line[0] == '*' || line[0] == '\r' || line[0] == '\r')
- return;
+ return 0;
while (1) {
str[0] = *ptr++;
@@ -49,7 +50,8 @@ static void convert_line(int fd, const char *line)
val = strtol(str, NULL, 16);
- write(fd, &val, 1);
+ if (write(fd, &val, 1) < 0)
+ return -errno;
if (*ptr == '\r' || *ptr == '\n')
break;
@@ -57,6 +59,8 @@ static void convert_line(int fd, const char *line)
while (*ptr == ' ')
ptr++;
}
+
+ return 0;
}
static void convert_file(const char *input_path, const char *output_path)
--
1.8.3.2
Hi,
On Mon, Jan 13, 2014 at 7:13 AM, Anderson Lizardo
<[email protected]> wrote:
> Hi Szymon/Johan,
>
> On Mon, Jan 13, 2014 at 4:48 AM, Johan Hedberg <[email protected]> wrote:
>> Hi Szymon,
>>
>> On Mon, Jan 13, 2014, Szymon Janc wrote:
>>> Don't ignore return value of write. This fix following build error on
>>> Ubuntu:
>>>
>>> tools/seq2bseq.c: In function ?convert_line?:
>>> tools/seq2bseq.c:52:8: error: ignoring return value of ?write?,
>>> declared with attribute warn_unused_result [-Werror=unused-result]
>>> write(fd, &val, 1);
>>> ---
>>> tools/seq2bseq.c | 10 +++++++---
>>> 1 file changed, 7 insertions(+), 3 deletions(-)
>>
>> Both patches have been applied. Thanks.
>
>
> I sent a similar patch a few hours ago (which was not applied). There
> you can see the caller of convert_line() also needs to be changed to
> break the parsing loop. I was also printing the error with perror
> (similar to other places on the file).
Oops, I've just seen the second patch. Sorry about the noise :)
Best Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
Hi Szymon/Johan,
On Mon, Jan 13, 2014 at 4:48 AM, Johan Hedberg <[email protected]> wrote:
> Hi Szymon,
>
> On Mon, Jan 13, 2014, Szymon Janc wrote:
>> Don't ignore return value of write. This fix following build error on
>> Ubuntu:
>>
>> tools/seq2bseq.c: In function ?convert_line?:
>> tools/seq2bseq.c:52:8: error: ignoring return value of ?write?,
>> declared with attribute warn_unused_result [-Werror=unused-result]
>> write(fd, &val, 1);
>> ---
>> tools/seq2bseq.c | 10 +++++++---
>> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> Both patches have been applied. Thanks.
I sent a similar patch a few hours ago (which was not applied). There
you can see the caller of convert_line() also needs to be changed to
break the parsing loop. I was also printing the error with perror
(similar to other places on the file).
Best Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
Hi Szymon,
On Mon, Jan 13, 2014, Szymon Janc wrote:
> Don't ignore return value of write. This fix following build error on
> Ubuntu:
>
> tools/seq2bseq.c: In function ‘convert_line’:
> tools/seq2bseq.c:52:8: error: ignoring return value of ‘write’,
> declared with attribute warn_unused_result [-Werror=unused-result]
> write(fd, &val, 1);
> ---
> tools/seq2bseq.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
Both patches have been applied. Thanks.
Johan
If write failed converted file would be broken. This make sure that
user is being informed about it.
---
tools/seq2bseq.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/tools/seq2bseq.c b/tools/seq2bseq.c
index 9797f5f..7657a57 100644
--- a/tools/seq2bseq.c
+++ b/tools/seq2bseq.c
@@ -130,6 +130,7 @@ static void convert_file(const char *input_path, const char *output_path)
while (1) {
char *str;
+ int err;
str = fgets(line_buffer, line_size - 1, fp);
if (!str)
@@ -137,7 +138,12 @@ static void convert_file(const char *input_path, const char *output_path)
cur += strlen(str);
- convert_line(fd, str);
+ err = convert_line(fd, str);
+ if (err < 0) {
+ fprintf(stderr, "Failed to convert file (%s)\n",
+ strerror(-err));
+ break;
+ }
}
fclose(fp);
--
1.8.3.2