From: Johan Hedberg <johan.hedberg@gmail.com>
To: Bartosz Szatkowski <bulislaw@linux.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH obexd 1/6] gobex: Add translating error codes to strings
Date: Thu, 8 Dec 2011 13:07:10 +0200 [thread overview]
Message-ID: <20111208110710.GD30533@x220> (raw)
In-Reply-To: <1323085309-23094-1-git-send-email-bulislaw@linux.com>
Hi Bartosz,
On Mon, Dec 05, 2011, Bartosz Szatkowski wrote:
> +struct error_code {
> + guint8 code;
> + const char *name;
> +} obex_errors[] = {
> + { G_OBEX_RSP_CONTINUE, "Continue" },
> + { G_OBEX_RSP_SUCCESS, "Success" },
> + { G_OBEX_RSP_CREATED, "Created" },
> + { G_OBEX_RSP_ACCEPTED, "Accepted" },
> + { G_OBEX_RSP_NON_AUTHORITATIVE, "Non Authoritative" },
> + { G_OBEX_RSP_NO_CONTENT, "No Content" },
> + { G_OBEX_RSP_RESET_CONTENT, "Reset Content" },
> + { G_OBEX_RSP_PARTIAL_CONTENT, "Partial Content" },
> + { G_OBEX_RSP_MULTIPLE_CHOICES, "Multiple Choices" },
> + { G_OBEX_RSP_MOVED_PERMANENTLY, "Moved Permanently" },
> + { G_OBEX_RSP_MOVED_TEMPORARILY, "Moved Temporarily" },
> + { G_OBEX_RSP_SEE_OTHER, "See Other" },
> + { G_OBEX_RSP_NOT_MODIFIED, "Not Modified" },
> + { G_OBEX_RSP_USE_PROXY, "Use Proxy" },
> + { G_OBEX_RSP_BAD_REQUEST, "Bad Request" },
> + { G_OBEX_RSP_UNAUTHORIZED, "Unauthorized" },
> + { G_OBEX_RSP_PAYMENT_REQUIRED, "Payment Required" },
> + { G_OBEX_RSP_FORBIDDEN, "Forbidden" },
> + { G_OBEX_RSP_NOT_FOUND, "Not Found" },
> + { G_OBEX_RSP_METHOD_NOT_ALLOWED, "Method Not Allowed" },
> + { G_OBEX_RSP_NOT_ACCEPTABLE, "Not Acceptable" },
> + { G_OBEX_RSP_PROXY_AUTH_REQUIRED, "Proxy Auth Required" },
> + { G_OBEX_RSP_REQUEST_TIME_OUT, "Request Time Out" },
> + { G_OBEX_RSP_CONFLICT, "Conflict" },
> + { G_OBEX_RSP_GONE, "Gone" },
> + { G_OBEX_RSP_LENGTH_REQUIRED, "Length Required" },
> + { G_OBEX_RSP_PRECONDITION_FAILED, "Precondition Failed" },
> + { G_OBEX_RSP_REQ_ENTITY_TOO_LARGE, "Req Entity Too Large" },
> + { G_OBEX_RSP_REQ_URL_TOO_LARGE, "Req Url Too Large" },
> + { G_OBEX_RSP_UNSUPPORTED_MEDIA_TYPE, "Unsupported Media Type" },
> + { G_OBEX_RSP_INTERNAL_SERVER_ERROR, "Internal Server Error" },
> + { G_OBEX_RSP_NOT_IMPLEMENTED, "Not Implemented" },
> + { G_OBEX_RSP_BAD_GATEWAY, "Bad Gateway" },
> + { G_OBEX_RSP_SERVICE_UNAVAILABLE, "Service Unavailable" },
> + { G_OBEX_RSP_GATEWAY_TIMEOUT, "Gateway Timeout" },
> + { G_OBEX_RSP_VERSION_NOT_SUPPORTED, "Version Not Supported" },
> + { G_OBEX_RSP_DATABASE_FULL, "Database Full" },
> + { G_OBEX_RSP_DATABASE_LOCKED, "Database Locked" },
> + { }
> +};
Could you indent the strings (with tabs) so that they all start at the
same column? That'd make it easier to read the table.
> +const char *g_obex_strerror(guint8 err_code)
> +{
> + struct error_code *error;
> +
> + for (error = obex_errors; error != NULL; error++)
> + if (error->code == err_code)
> + return error->name;
> +
> + return "<unknown>";
> +}
I guess you never tested this function with a code that's not in the
table? The loop will go past the end in such a case. You're assigning a
pointer to the table in the beginning and then just incrementing the
pointer. What makes you think that the pointer would magically become
NULL suddenly? What would work is if you make the last entry
{ 0x00, NULL }, and then check for error->name != NULL in the for-loop.
Johan
next prev parent reply other threads:[~2011-12-08 11:07 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-05 11:41 [PATCH obexd 1/6] gobex: Add translating error codes to strings Bartosz Szatkowski
2011-12-05 11:41 ` [PATCH obexd 2/6] Add basic support for MAP client in obex-client Bartosz Szatkowski
2011-12-05 11:41 ` [PATCH obexd 3/6] Add support for SetFolder in MAP client Bartosz Szatkowski
2011-12-05 11:41 ` [PATCH obexd 4/6] Add simple helper for " Bartosz Szatkowski
2011-12-05 11:41 ` [PATCH obexd 5/6] Add basic support for MAP folder listing Bartosz Szatkowski
2011-12-05 11:41 ` [PATCH obexd 6/6] Add support for PullMessagesListing in MAP client Bartosz Szatkowski
2011-12-08 11:07 ` Johan Hedberg [this message]
-- strict thread matches above, loose matches on Subject: below --
2011-12-08 13:07 [PATCH obexd 1/6] gobex: Add translating error codes to strings Bartosz Szatkowski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111208110710.GD30533@x220 \
--to=johan.hedberg@gmail.com \
--cc=bulislaw@linux.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).