Sponsored Content
Full Discussion: strcat outputs garbage
Top Forums Programming strcat outputs garbage Post 302424528 by jim mcnamara on Tuesday 25th of May 2010 01:42:23 PM
Old 05-25-2010
You need to initilaize your strings
Code:
char temp[32]={0x0};
char tempHolder[32]={0x0};

The reason strcat() "messes up" is because there were pre-existing garbage bytes on the stack where temp was allocated. strcat moved on past the garbage to the first '\0' byte to write the content of tempHolder.
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Garbage characters in display

:confused: I recently left managment and came back to AIX administration. So I am a bit rusty to say the least. The issue I am having is with the term settings when I either simply telnet to my AIX unit or even when I use an emulator like puTTY or a VAR provided one. Once I am logged into... (0 Replies)
Discussion started by: Haleja001
0 Replies

2. Programming

strcat() dumping core

strcat dumping core in the situation like main() { char* item; char* p=sat_item; char type; item=(char*) malloc(strlen(p)); strncpy(type,p,4); type='\0'; strcat(item,type); //dumping core } I couldn't get why strcat dumping core? (3 Replies)
Discussion started by: satish@123
3 Replies

3. Programming

`strcat' makes pointer from integer without a cast

A question to ask. seq1 = "eeeeeeeeeeeeeeeeee"; seq2 = "dddddddddddddddddddd"; char a = '*'; strcat(*seq2, &a); strcat(*seq1, seq2); compilation warning: passing arg 1 of `strcat' makes pointer from integer without a cast thanks (4 Replies)
Discussion started by: cdbug
4 Replies

4. Shell Programming and Scripting

strcat equivalent in shell scripting

Hi all, How does string concatenation work in shell scripting? I basically have a variable called "string" and I want to add the strings "aaa" "bbb" "ccc" "ddd" to the variable "string". These strings would be added based on some conditions and separated by spaces . So "string" might look... (8 Replies)
Discussion started by: felixmat1
8 Replies

5. Shell Programming and Scripting

create outputs from other command outputs

hi friends, The code: i=1 while do filename=`/usr/bin/ls -l| awk '{ print $9}'` echo $filename>>summary.csv #Gives the name of the file stored at column 9 count=`wc -l $filename | awk '{print $1}'` echo $count>>summary.csv #Gives just the count of lines of file "filename" i=`expr... (1 Reply)
Discussion started by: rajsharma
1 Replies

6. Shell Programming and Scripting

Garbage value

I write a program to find a palindromic region in given sequences. but it dosen't seems to be run well. please give me your suggestions INPUT: AGCTAGCTCGAAGGTAG code is here #!/usr/bin/perl #Palindromic sequence print "enter the sequence:\n"; $rna = <STDIN>; chomp $rna; ... (3 Replies)
Discussion started by: sujit_singh
3 Replies

7. Programming

strcat in C

Hello, #include <stdio.h> #include <string.h> void main() { char tab={"12"}; FILE *outfile; char *outname = "/home/dir/"; printf("%s",strcat(outname,tab)); outfile = fopen(strcat(outname,tab), "w"); if (!outfile) { printf("There was a problem opening %s for writing\n", outname); ... (2 Replies)
Discussion started by: chercheur857
2 Replies

8. Programming

Boehm garbage collector for C

is anybody out there experienced with the boehm gc? this is a very simple function: int fn1(){ int *p = (int *) GC_MALLOC(sizeof(int *)); return 0; }after leaving fn1() gc should free p. *** now another example: int* fn2(){ int* p= (int *) GC_MALLOC(sizeof(int... (1 Reply)
Discussion started by: dodona
1 Replies

9. UNIX for Beginners Questions & Answers

Some % of Garbage Collection

I need to write a python script that will look at the local gc logs. 6 sys=0.00, real=0.06 secs] 2019-06-05T07:43:12.029-0500: 1072696.494: 2791209K->1995953K(2796544K)] 2803355K->1995953K(4164608K), , 3.0299555 secs] 2019-06-05T07:43:17.149-0500: 1072701.614: 3334321K->2008193K(4167680K),... (1 Reply)
Discussion started by: xgringo
1 Replies
STRCAT(3)						   BSD Library Functions Manual 						 STRCAT(3)

NAME
strcat, strncat -- concatenate strings LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <string.h> char * strcat(char *restrict s1, const char *restrict s2); char * strncat(char *restrict s1, const char *restrict s2, size_t n); DESCRIPTION
The strcat() and strncat() functions append a copy of the null-terminated string s2 to the end of the null-terminated string s1, then add a terminating ''. The string s1 must have sufficient space to hold the result. The strncat() function appends not more than n characters from s2, and then adds a terminating ''. The source and destination strings should not overlap, as the behavior is undefined. RETURN VALUES
The strcat() and strncat() functions return the pointer s1. SECURITY CONSIDERATIONS
The strcat() function is easily misused in a manner which enables malicious users to arbitrarily change a running program's functionality through a buffer overflow attack. (See the FSA.) Avoid using strcat(). Instead, use strncat() or strlcat() and ensure that no more characters are copied to the destination buffer than it can hold. Note that strncat() can also be problematic. It may be a security concern for a string to be truncated at all. Since the truncated string will not be as long as the original, it may refer to a completely different resource and usage of the truncated resource could result in very incorrect behavior. Example: void foo(const char *arbitrary_string) { char onstack[8] = ""; #if defined(BAD) /* * This first strcat is bad behavior. Do not use strcat! */ (void)strcat(onstack, arbitrary_string); /* BAD! */ #elif defined(BETTER) /* * The following two lines demonstrate better use of * strncat(). */ (void)strncat(onstack, arbitrary_string, sizeof(onstack) - strlen(onstack) - 1); #elif defined(BEST) /* * These lines are even more robust due to testing for * truncation. */ if (strlen(arbitrary_string) + 1 > sizeof(onstack) - strlen(onstack)) err(1, "onstack would be truncated"); (void)strncat(onstack, arbitrary_string, sizeof(onstack) - strlen(onstack) - 1); #endif } SEE ALSO
bcopy(3), memccpy(3), memcpy(3), memmove(3), strcpy(3), strlcat(3), strlcpy(3) STANDARDS
The strcat() and strncat() functions conform to ISO/IEC 9899:1990 (``ISO C90''). BSD
June 4, 1993 BSD
All times are GMT -4. The time now is 04:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy