[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/3] Fix compilation problems associated with -Wunused-result and
From: |
Brad Hards |
Subject: |
[PATCH 1/3] Fix compilation problems associated with -Wunused-result and -Werror |
Date: |
Mon, 30 May 2011 12:40:20 +1000 |
These warnings are a bit excessive, but they are enabled by default on
some systems (e.g. Ubuntu) with some compilers (gcc 4.5.2 in my case).
Signed-off-by: Brad Hards <address@hidden>
---
examples/client-callback.c | 14 +++++++++++---
examples/client-mech.c | 16 +++++++++++++---
examples/client-serverfirst.c | 7 ++++++-
examples/client.c | 7 ++++++-
src/imap.c | 12 +++++++++---
src/smtp.c | 12 +++++++++---
6 files changed, 54 insertions(+), 14 deletions(-)
diff --git a/examples/client-callback.c b/examples/client-callback.c
index ee014f7..4925802 100644
--- a/examples/client-callback.c
+++ b/examples/client-callback.c
@@ -36,8 +36,11 @@ client_authenticate (Gsasl_session * session)
do
{
+ char *res;
printf ("Input base64 encoded data from server:\n");
- fgets (buf, sizeof (buf) - 1, stdin);
+ res = fgets (buf, sizeof (buf) - 1, stdin);
+ if (res == NULL)
+ buf[0] = '\0';
if (buf[strlen (buf) - 1] == '\n')
buf[strlen (buf) - 1] = '\0';
@@ -91,6 +94,7 @@ callback (Gsasl * ctx, Gsasl_session * sctx, Gsasl_property
prop)
{
char buf[BUFSIZ] = "";
int rc = GSASL_NO_CALLBACK;
+ char *res;
/* Get user info from user. */
@@ -100,7 +104,9 @@ callback (Gsasl * ctx, Gsasl_session * sctx, Gsasl_property
prop)
{
case GSASL_PASSCODE:
printf ("Enter passcode:\n");
- fgets (buf, sizeof (buf) - 1, stdin);
+ res = fgets (buf, sizeof (buf) - 1, stdin);
+ if (res == NULL)
+ buf[0] = '\0';
buf[strlen (buf) - 1] = '\0';
gsasl_property_set (sctx, GSASL_PASSCODE, buf);
@@ -109,7 +115,9 @@ callback (Gsasl * ctx, Gsasl_session * sctx, Gsasl_property
prop)
case GSASL_AUTHID:
printf ("Enter username:\n");
- fgets (buf, sizeof (buf) - 1, stdin);
+ res = fgets (buf, sizeof (buf) - 1, stdin);
+ if (res == NULL)
+ buf[0] = '\0';
buf[strlen (buf) - 1] = '\0';
gsasl_property_set (sctx, GSASL_AUTHID, buf);
diff --git a/examples/client-mech.c b/examples/client-mech.c
index aac3a96..dc56bfc 100644
--- a/examples/client-mech.c
+++ b/examples/client-mech.c
@@ -36,8 +36,13 @@ client_authenticate (Gsasl_session * session)
do
{
+ char *res;
printf ("Input base64 encoded data from server:\n");
- fgets (buf, sizeof (buf) - 1, stdin);
+ res = fgets (buf, sizeof (buf) - 1, stdin);
+ if (res == NULL) {
+ buf[0] = '\n';
+ buf[1] = '\0';
+ }
if (buf[strlen (buf) - 1] == '\n')
buf[strlen (buf) - 1] = '\0';
@@ -71,16 +76,21 @@ client_mechanism (Gsasl * ctx)
static char mech[GSASL_MAX_MECHANISM_SIZE + 1] = "";
char mechlist[BUFSIZ] = "";
const char *suggestion;
+ char *res;
printf ("Enter list of server supported mechanisms, separate by SPC:\n");
- fgets (mechlist, sizeof (mechlist) - 1, stdin);
+ res = fgets (mechlist, sizeof (mechlist) - 1, stdin);
+ if (res == NULL)
+ mechlist[0] = '\0';
suggestion = gsasl_client_suggest_mechanism (ctx, mechlist);
if (suggestion)
printf ("Library suggests use of `%s'.\n", suggestion);
printf ("Enter mechanism to use:\n");
- fgets (mech, sizeof (mech) - 1, stdin);
+ res = fgets (mech, sizeof (mech) - 1, stdin);
+ if (res == NULL)
+ mech[0] = '\0';
mech[strlen (mech) - 1] = '\0';
return mech;
diff --git a/examples/client-serverfirst.c b/examples/client-serverfirst.c
index 987d255..a116de8 100644
--- a/examples/client-serverfirst.c
+++ b/examples/client-serverfirst.c
@@ -36,8 +36,13 @@ client_authenticate (Gsasl_session * session)
do
{
+ char *res;
printf ("Input base64 encoded data from server:\n");
- fgets (buf, sizeof (buf) - 1, stdin);
+ res = fgets (buf, sizeof (buf) - 1, stdin);
+ if (res == NULL) {
+ buf[0] = '\n';
+ buf[1] = '\0';
+ }
if (buf[strlen (buf) - 1] == '\n')
buf[strlen (buf) - 1] = '\0';
diff --git a/examples/client.c b/examples/client.c
index a45013c..f55782c 100644
--- a/examples/client.c
+++ b/examples/client.c
@@ -49,8 +49,13 @@ client_authenticate (Gsasl_session * session)
if (rc == GSASL_NEEDS_MORE)
{
/* If the client need more data from server, get it here. */
+ char *res;
printf ("Input base64 encoded data from server:\n");
- fgets (buf, sizeof (buf) - 1, stdin);
+ res = fgets (buf, sizeof (buf) - 1, stdin);
+ if (res == NULL) {
+ buf[0] = '\n';
+ buf[1] = '\0';
+ }
if (buf[strlen (buf) - 1] == '\n')
buf[strlen (buf) - 1] = '\0';
}
diff --git a/src/imap.c b/src/imap.c
index 6affa41..c7bc3ed 100644
--- a/src/imap.c
+++ b/src/imap.c
@@ -110,8 +110,11 @@ imap_authenticate (const char *mech)
{
char *buf;
int rc;
+ int len;
- asprintf (&buf, ". AUTHENTICATE %s", mech);
+ len = asprintf (&buf, ". AUTHENTICATE %s", mech);
+ if (len < 0)
+ return 0;
rc = writeln (buf);
free (buf);
if (!rc)
@@ -126,11 +129,14 @@ imap_step_send (const char *data)
{
char *buf;
int rc;
+ int len;
if (args_info.server_flag)
- asprintf (&buf, "+ %s", data);
+ len = asprintf (&buf, "+ %s", data);
else
- asprintf (&buf, "%s", data);
+ len = asprintf (&buf, "%s", data);
+ if (len < 0)
+ return 0;
rc = writeln (buf);
free (buf);
if (!rc)
diff --git a/src/smtp.c b/src/smtp.c
index c76a9c7..b14ab33 100644
--- a/src/smtp.c
+++ b/src/smtp.c
@@ -114,8 +114,11 @@ smtp_authenticate (const char *mech)
{
char *buf;
int rc;
+ int len;
- asprintf (&buf, "AUTH %s", mech);
+ len = asprintf (&buf, "AUTH %s", mech);
+ if (len < 0)
+ return 0;
rc = writeln (buf);
free (buf);
if (!rc)
@@ -130,11 +133,14 @@ smtp_step_send (const char *data)
{
char *buf;
int rc;
+ int len;
if (args_info.server_flag)
- asprintf (&buf, "334 %s", data);
+ len = asprintf (&buf, "334 %s", data);
else
- asprintf (&buf, "%s", data);
+ len = asprintf (&buf, "%s", data);
+ if (len < 0)
+ return 0;
rc = writeln (buf);
free (buf);
if (!rc)
--
1.7.4.1
- [PATCH 1/3] Fix compilation problems associated with -Wunused-result and -Werror,
Brad Hards <=