From: Joakim Tjernlund <Joakim.Tjernlund@infinera.com>
To: "rasmus.villemoes@prevas.dk" <rasmus.villemoes@prevas.dk>,
"schwab@linux-m68k.org" <schwab@linux-m68k.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: printk of non NULL terminated strings ?
Date: Thu, 9 Jul 2020 15:28:41 +0000 [thread overview]
Message-ID: <450b6c9326cf28c9377b2b2be125e1d93be0fb31.camel@infinera.com> (raw)
In-Reply-To: <4d081ee7-5527-f821-5e9e-87ff053f7d2d@prevas.dk>
On Thu, 2020-07-09 at 15:30 +0200, Rasmus Villemoes wrote:
> On 09/07/2020 15.26, Joakim Tjernlund wrote:
> > On Thu, 2020-07-09 at 14:56 +0200, Andreas Schwab wrote:
> > > CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.
> > >
> > >
> > > On Jul 09 2020, Joakim Tjernlund wrote:
> > >
> > > > Is there a format (or other function) that lets me
> > > > print strings without an \0 terminator using an explicit length arg instead?
> > >
> > > Use the precision.
> >
> > Looking at that now but have a hard time figuring how to use it, can you give me an example?
>
> Exactly as you'd do in userspace:
>
> printf("%.*s\n", len, buf)
>
> Of course, vsnprintf() will still stop if it encounters a nul byte
> within those first len bytes in buf. And you need len to have type int,
> so you may need a cast if you have a size_t or ssize_t or whatnot.
Thanks, this did the trick :)
prev parent reply other threads:[~2020-07-09 15:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-09 12:31 Joakim Tjernlund
2020-07-09 12:56 ` Andreas Schwab
2020-07-09 13:26 ` Joakim Tjernlund
2020-07-09 13:30 ` Rasmus Villemoes
2020-07-09 15:28 ` Joakim Tjernlund [this message]
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=450b6c9326cf28c9377b2b2be125e1d93be0fb31.camel@infinera.com \
--to=joakim.tjernlund@infinera.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rasmus.villemoes@prevas.dk \
--cc=schwab@linux-m68k.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
all inboxes | Powered by JetHome®