ALT Linux Community general discussions
 help / color / mirror / Atom feed
From: Dmitry Vodennikov <vod@elecom.ru>
To: shigorin@gmail.com, ALT Linux Community <community@lists.altlinux.org>
Subject: Re: [Comm] alm2.4 "watch" bug?
Date: Tue, 04 Apr 2006 01:36:28 -0700
Message-ID: <4432300C.2080605@elecom.ru> (raw)
In-Reply-To: <20060403094313.GK1617@osdn.org.ua>

Michael Shigorin пишет:
> On Fri, Mar 31, 2006 at 09:53:36PM -0800, Dmitry Vodennikov wrote:
>>> * Срд Авг 11 2004 Stanislav Ievlev <inger@altlinux> 2.0.10-alt4.1
>>> - setlocale in watch to see output with national symbols (e.g. russian)
>>> Не оно?
>> Не похоже.
> 
> Как по мне -- так похоже, в корне-то не-ASCII нет небось.
> Повесьте эти письма в bugzilla на ALM2.4, что ли.
> 
Я щас повешу багу с локализованной проблемой и решением.

Проблема с watch.c состоит в следующем. Смотрим watch.c
-------------------------------------------------
         command = strdup(argv[optind++]);
         command_length = strlen(command);
         for (; optind < argc; optind++) {
                 int s = strlen(argv[optind]);
                 char *endp = &command[command_length];
                 *endp = ' ';
                 command_length += s + 1;
                 command = realloc(command, command_length + 1);
                 strcpy(endp + 1, argv[optind]);
         }
-------------------------------------------------
man realloc говорит нам вот что
realloc() returns a pointer to the newly  allocated  memory,  which  is
suitably  aligned  for  any  kind of variable and may be different from
ptr
собственно, так оно и видно под отладчиком. realloc возвращает 
совершенно другой указатель, что в сочетании с установкой endp ДО 
realloc и записью в *endp ПОСЛЕ realloc приводит к неожиданным эффектам.

у меня например это приводило к segmentation fault, если параметр у ls 
длиннее 8 символов. Т.е.
export LANG=ru_RU.CP1251 watch ls 12345678
работает, а
export LANG=ru_RU.CP1251 watch ls 123456789
уже нет

Ну собственно остается только сказать что в сизифном procsp этот кусок 
уже переделан вот так:
-------------------------------------------------
                 char *endp;
                 int s = strlen(argv[optind]);
                 command = realloc(command, command_length + s + 2); 
  /* space and \0 */
                 endp = command + command_length;
                 *endp = ' ';
                 memcpy(endp + 1, argv[optind], s);
                 command_length += 1 + s;        /* space then string 
length */
                 command[command_length] = '\0';
-------------------------------------------------



  parent reply	other threads:[~2006-04-04  8:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-31  5:47 Dmitry Vodennikov
2006-03-31  6:50 ` Evgenii Terechkov
2006-03-31 15:04 ` Andrey Rahmatullin
2006-03-31 15:52   ` Evgenii Terechkov
2006-04-01  5:53   ` Dmitry Vodennikov
2006-04-01  6:02     ` Andrey Rahmatullin
2006-04-03  9:43     ` Michael Shigorin
2006-04-03 15:28       ` Andrey Rahmatullin
2006-04-03 16:04         ` Evgenii Terechkov
2006-04-04  8:36       ` Dmitry Vodennikov [this message]
2006-04-04  8:53         ` Michael Shigorin
2006-04-04  9:20           ` Dmitry Vodennikov

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=4432300C.2080605@elecom.ru \
    --to=vod@elecom.ru \
    --cc=community@lists.altlinux.org \
    --cc=shigorin@gmail.com \
    /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

ALT Linux Community general discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/community/0 community/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 community community/ http://lore.altlinux.org/community \
		mandrake-russian@linuxteam.iplabs.ru community@lists.altlinux.org community@lists.altlinux.ru community@lists.altlinux.com
	public-inbox-index community

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.community


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git