linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan-Benedict Glaw <jbglaw@lug-owl.de>
To: Linux devellist <linux-c-programming@vger.kernel.org>
Subject: Re: Some question about one method.
Date: Fri, 21 May 2004 23:19:30 +0200	[thread overview]
Message-ID: <20040521211930.GQ1912@lug-owl.de> (raw)
In-Reply-To: <53BBBB3235C2C74583722B212B36CA0D61F909@vishnu.ctd.hcltech.com>

[-- Attachment #1: Type: text/plain, Size: 1080 bytes --]

On Fri, 2004-05-21 16:24:23 +0530, Ranga Reddy M - CTD ,Chennai. <rangareddym@ctd.hcltech.com>
wrote in message <53BBBB3235C2C74583722B212B36CA0D61F909@vishnu.ctd.hcltech.com>:
> Hi,
> 
> char ch[1];
> ch[0]=(char) sym;
> ch[1]='\0';
> 
> strcat(tmp,ch);
> 
> usage of the strcat as you mentioned.
> But, how fast this is going to be I have no idea.

Whoops, off by one! That's a bad (read as wrong and possibly even a
security relevant bug). You declared "ch"  to be an array with one
element, that's ch[0]. So you're not allowed to assign anything to
ch[1]. If you need two bytes, just ask for that.

Remember, inside the braces you put number of elements. It's not the
highest useable index (which is one less than number of elements).

MfG, JBG

-- 
   Jan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481
   "Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg
    fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!
   ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

  reply	other threads:[~2004-05-21 21:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-21 10:54 Some question about one method Ranga Reddy M - CTD ,Chennai.
2004-05-21 21:19 ` Jan-Benedict Glaw [this message]
  -- strict thread matches above, loose matches on Subject: below --
2004-05-21 10:24 Alphex Kaanoken
2004-05-21 21:17 ` Jan-Benedict Glaw
2004-05-24  8:06   ` Charlie Gordon
2004-05-24 17:30     ` Jan-Benedict Glaw
2004-05-24 23:24       ` Charlie Gordon
2004-05-25  0:06         ` Jeff Woods
2004-05-25  0:41         ` Glynn Clements

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=20040521211930.GQ1912@lug-owl.de \
    --to=jbglaw@lug-owl.de \
    --cc=linux-c-programming@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).