delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/07/05/09:33:38

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Date: Tue, 5 Jul 2005 15:33:33 +0200
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: Bug with strcat
Message-ID: <20050705133333.GA21074@calimero.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <BAY19-F312C3374BC4C555D2BB846A5E60 AT phx DOT gbl>
Mime-Version: 1.0
In-Reply-To: <BAY19-F312C3374BC4C555D2BB846A5E60@phx.gbl>
User-Agent: Mutt/1.4.2i

On Jul  5 10:11, Ivan Mari wrote:
> This code produces an access violation.

Yep, no wonder.
>  Commenting out the arr[] it works 
> fine. Leaving the arr[]  and commenting out the strcat works too.
> Anyway on a Linux with GCC 3.4.2 it works as it is presented here without 
> problems

Only coincidentally.

> #include <stdarg.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> 
> int main()
> {
> 
>        int arr[] = {1,2,3,4,5};
> 
>        char *buf = (char *) malloc (80);
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	 Using malloc does *not* initialize the allocated area to all zero.

>        if (buf == ((void *)0))
>                printf("LKD error: Not enough memory\n");
> 
>   		int a = 20;
> 
> 		{char tempBuffer[80];int bsize;snprintf (tempBuffer,80, 
                                     ^^^^^^^^^
				     uninitialized auto variable

> 		"Ivan %d", a );bsize += strlen(tempBuffer) + 1; buf = (char *) realloc 
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
			      adding a value to an uninitialized auto variable

> (buf, bsize); strcat(buf, tempBuffer);}
                ^^^^^^^^^^^^^^^^^^^^^^^
		Using strcat on an uninitialized buffer

> 
> return 0;
> }


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          mailto:cygwin AT cygwin DOT com
Red Hat, Inc.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019