From: Nico Golde <nico@ngolde.de>
To: trinity@vger.kernel.org
Subject: Re: minor trinity patch
Date: Fri, 21 Jun 2013 15:20:46 +0200 [thread overview]
Message-ID: <20130621132046.GS26707@ngolde.de> (raw)
In-Reply-To: <CA+ydwtqCfUJhq-g-wG442GAs3yyTTfi3xnUNwgDfnGiWqh5D3w@mail.gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 966 bytes --]
Hi,
* Tommi Rantala <tt.rantala@gmail.com> [2013-06-03 07:56]:
> 2013/5/24 Nico Golde <nico@ngolde.de>:
> > * Tommi Rantala <tt.rantala@gmail.com> [2013-05-23 20:58]:
> >> 2013/5/22 Nico Golde <nico@ngolde.de>:
> >> > I changed the code the following way:
> >> > @@ -21,7 +22,8 @@ static size_t bldevs, chrdevs, miscdevs;
> >> > static void parse_proc_devices(void)
> >> > {
> >> > FILE *fp;
> >> > - char *name, *line = NULL;
> >> > + char *line = NULL;
> >> > + char name[32];
> >>
> >> It would be IMO preferable to not hardcode the max length.
> >
> > I agree, this is actually left over from quickly changing this.
> > Are you aware of a proper maximum defined in the kernel headers or do we want to
> > allocate this completely dynamically?
>
> dynamic please!
Sorry I had no time to look into this for a while.
Patch attached.
Cheers
Nico
--
Nico Golde - XMPP: nion@jabber.ccc.de - GPG: 0xA0A0AAAA
[-- Attachment #1.2: 0001-devices.c-dont-use-as-scanf-format-string-but-instea.patch --]
[-- Type: text/x-diff, Size: 1287 bytes --]
From 9acc7c59c6ae2643ffba4edc17b04477f5cdaee0 Mon Sep 17 00:00:00 2001
From: Nico Golde <nion@debian.org>
Date: Fri, 21 Jun 2013 15:18:58 +0200
Subject: [PATCH] devices.c: dont use %as scanf format string, but instead
allocate and parse the device name manually for
compatibility with non-glibc libcs
---
devices.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/devices.c b/devices.c
index 43433bc..d3916f9 100644
--- a/devices.c
+++ b/devices.c
@@ -21,7 +21,7 @@ static size_t bldevs, chrdevs, miscdevs;
static void parse_proc_devices(void)
{
FILE *fp;
- char *name, *line = NULL;
+ char *p, *name, *line = NULL;
size_t n = 0;
int block, major;
void *new;
@@ -35,7 +35,14 @@ static void parse_proc_devices(void)
while (getline(&line, &n, fp) >= 0) {
if (strcmp("Block devices:\n", line) == 0)
block = 1;
- else if (sscanf(line, "%d %as", &major, &name) == 2) {
+ else if (strcmp("Character devices:\n", line) == 0)
+ block = 0;
+ else if (sscanf(line, "%d %*s", &major) == 1) {
+ if ((p = strrchr(line, ' ')) == NULL)
+ continue;
+ p++;
+ name = strdup(p);
+
if (block) {
new = realloc(block_devs, (bldevs+1)*sizeof(*block_devs));
if (!new) {
--
1.7.10.4
[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]
next prev parent reply other threads:[~2013-06-21 13:20 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20121220165100.GA8748@ngolde.de>
[not found] ` <20121220171726.GA7543@redhat.com>
[not found] ` <20121220172246.GA16285@ngolde.de>
[not found] ` <20121220172741.GA17760@redhat.com>
[not found] ` <20121220200255.GB16285@ngolde.de>
[not found] ` <20121220201903.GA14944@redhat.com>
2013-05-22 14:14 ` minor trinity patch Nico Golde
2013-05-23 18:58 ` Tommi Rantala
2013-05-23 23:47 ` Nico Golde
2013-06-03 5:55 ` Tommi Rantala
2013-06-21 13:20 ` Nico Golde [this message]
2013-06-24 16:03 ` Nico Golde
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=20130621132046.GS26707@ngolde.de \
--to=nico@ngolde.de \
--cc=trinity@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