[notmuch] [PATCH] fix compiler warnings

2009-11-23 Thread Carl Worth
On Sun, 22 Nov 2009 17:11:03 +0200, Dirk-Jan C. Binnema  wrote:
> 
> (hopefully this is the correct way to send patches...)

Looks just fine, and welcome to notmuch!

> With these minor changes, notmuch compiles warning-free with gcc 4.4.1

Could you resend these as separate patches, each patch fixing a single
type of warning? That would make it more clear what the code is doing.

> -write(2, msg, sizeof(msg)-1);
> +if (write(2, msg, sizeof(msg)-1) < 0) {
> + /* ignore...*/
> +}

I don't like the gratuitous conditional here. It clutters the code and
make is less clear. If we're just trying to squelch a warning about an
unused return value from a function, then I think I'd rather see:

ssize_t ignored;

ignored = write (2, msg, sizeof (msg) - 1);

What do you think?

-Carl


[notmuch] [PATCH] fix compiler warnings

2009-11-22 Thread Jeffrey Ollie
On Sun, Nov 22, 2009 at 9:22 PM, Carl Worth  wrote:
> On Sun, 22 Nov 2009 17:11:03 +0200, Dirk-Jan C. Binnema  gmail.com> wrote:
>>
>> - ? ?write(2, msg, sizeof(msg)-1);
>> + ? ?if (write(2, msg, sizeof(msg)-1) < 0) {
>> + ? ? ? ? /* ignore...*/
>> + ? ?}
>
> I don't like the gratuitous conditional here. It clutters the code and
> make is less clear. If we're just trying to squelch a warning about an
> unused return value from a function, then I think I'd rather see:
>
> ? ? ? ?ssize_t ignored;
>
> ? ? ? ?ignored = write (2, msg, sizeof (msg) - 1);

Isn't the usual method for ignoring return values casting to void?

(void) write (2, msg, sizeof (msg) - 1);

-- 
Jeff Ollie


[notmuch] [PATCH] fix compiler warnings

2009-11-22 Thread Dirk-Jan C. Binnema

(hopefully this is the correct way to send patches...)

With these minor changes, notmuch compiles warning-free with gcc 4.4.1

---
 notmuch-new.c   |4 +++-
 notmuch-setup.c |   13 +++--
 notmuch-tag.c   |4 +++-
 3 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/notmuch-new.c b/notmuch-new.c
index 0dd2784..88b48a6 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -36,7 +36,9 @@ static void
 handle_sigint (unused (int sig))
 {
 static char msg[] = "Stopping... \n";
-write(2, msg, sizeof(msg)-1);
+if (write(2, msg, sizeof(msg)-1) < 0) {
+   /* ignore...*/
+}
 interrupted = 1;
 }

diff --git a/notmuch-setup.c b/notmuch-setup.c
index 482efd2..0d3f186 100644
--- a/notmuch-setup.c
+++ b/notmuch-setup.c
@@ -99,12 +99,13 @@ notmuch_setup_command (unused (void *ctx),
 unsigned int i;
 int is_new;

-#define prompt(format, ...)\
-do {   \
-   printf (format, ##__VA_ARGS__); \
-   fflush (stdout);\
-   getline (, _size, stdin); \
-   chomp_newline (response);   \
+#define prompt(format, ...)\
+do {   \
+   printf (format, ##__VA_ARGS__); \
+   fflush (stdout);\
+   if (getline (, _size, stdin) < 0) \
+   break;  \
+   chomp_newline (response);   \
 } while (0)

 config = notmuch_config_open (ctx, NULL, _new);
diff --git a/notmuch-tag.c b/notmuch-tag.c
index e2311f6..5e40f50 100644
--- a/notmuch-tag.c
+++ b/notmuch-tag.c
@@ -26,7 +26,9 @@ static void
 handle_sigint (unused (int sig))
 {
 static char msg[] = "Stopping... \n";
-write(2, msg, sizeof(msg)-1);
+if (write(2, msg, sizeof(msg)-1) < 0) {
+   /* ignore... */
+}
 interrupted = 1;
 }

-- 
1.6.3.3