Questions tagged [strcat-s]

strcat_s is a proposed safer version of strcat

In C programming, strcat_s is a safe version of the strcat function. Along with strcpy_s this functions (defined in the ISO/IEC TR 24731 [PDF]) add an additional argument that specifies the maximum size of the destination and a return value that indicates whether the operation was successful

This function is supported in Microsoft's C library among others but there are criticism to the ISO proposal in general and, for example, glibc has not adopted them.

See: Do you use the TR 24731 'safe' functions?

14 questions
6
votes
7 answers

Why does MSVC++ consider "std::strcat" to be "unsafe"? (C++)

When I try to do things like this: char* prefix = "Sector_Data\\sector"; char* s_num = "0"; std::strcat(prefix, s_num); std::strcat(prefix, "\\"); and so on and so forth, I get a warning warning C4996: 'strcat': This function or variable may be…
user98188
6
votes
6 answers

strcat in c program is not working

#include #include void main() { char *str1="hello"; char *str2="world"; strcat(str2,str1); printf("%s",str2); } If I run this program, I'm getting run time program termination. Please help me. If I use this: char…
user3815049
4
votes
6 answers

Add string to string in C with safe functions

I want to copy the a file name to a string and append ".cpt" to it. But I am unable to do this with safe functions (strcat_s). Error: "String is not null terminated!". And I did set '\0', how to fix this using safe functions? size =…
user1502256
3
votes
2 answers

Why do i gett warnings by using strcpy_s and strcat_s?

I programmed an example on my Win64 PC with code:blocks using strcpy_s and strcat_s. The program works, but I get the warning messages "warning: implicit declaration of function 'strcpy_s' for strc_s and strcat_s respectively. The compiler settings…
Heimo
  • 39
  • 2
3
votes
4 answers

In what library is strcat_s?

I tried including string.h and stdlib.h, but still get undefined reference compile errors. This leads me to conclude that it is in a different library that I didn't include. Where is it? I am using gcc compiler - the code is written in Windows, but…
Sunspawn
  • 817
  • 1
  • 12
  • 27
1
vote
2 answers

Error that the stack was damaged while using strcat_s

I was studying strcat_s and I wrote the following code to practice it. int main(void) { char szPath[128] = { "C:\\Program Files\\" }; strcat_s(szPath + strlen("C:\\Program Files\\"), sizeof(szPath), "CHS\\"); strcat_s(szPath +…
1
vote
2 answers

Does strcat_s() require the use of realloc()?

Take the example code*: char *string = (char*)malloc(sizeof(char)); strcat_s(string, strlen(string) + 10 + 1, "characters"); The above code compiles and runs, leading me to believe that memory reallocation is taking place. However when applied on a…
0
votes
1 answer

Basic use of strcpy_s , strcat_s

Code char* CreateString(char* string1, char* string2) { int length = strlen(string1) + strlen(string2); // Allocate memory for the resulting string char* result = malloc((length) * sizeof(char)); // Concatenate the two…
0
votes
1 answer

Memory error with type L"" in Win32

Here's the code for my paint method in my Win32 project: case WM_PAINT: _tcscat_s(greeting, sizeof(greeting), LoadedFile); hdc = BeginPaint(hWnd, &ps); TextOut(hdc, 5, 5, greeting, _tcslen(greeting)); …
user6191359
  • 69
  • 1
  • 9
0
votes
3 answers

C - Error with strcat

What's the error in this code? I've got an error error C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead What it's mean? Another question - the declaration of the struct and the function prototype is…
Dvir Naim
  • 335
  • 1
  • 3
  • 12
0
votes
2 answers

application crashes at first strcat_s

I have tried both strcat and strcat_s, but they both crash. Does anyone know why this happens? I can't find the problem. Crash: "Unhandled exception at 0x58636D2A (msvcr110d.dll)" _Dst 0x00ea6b30 "C:\\Users\\Ruben\\Documents\\School\\" char…
user1502256
-1
votes
2 answers

strcat_s and char pointer newbie issue

I'm doing simple c excercise using visual studio. Using strcat_s function I receive a violation exception thru this code: char *str1; str1 = (char *)malloc(20); *str1 = "Ciao "; char *str2 = "Marco"; strcat_s(str1, sizeof(str1), str2); printf("%s",…
Marco
  • 27
  • 6
-3
votes
1 answer

Does strcat() return an error as strcat_s() does?

Does strcat() return an error as strcat_s() does? Can strcat() replace strcat_s()`? char str1[50] = "To be, or not to be, "; char str2[] = "that is the question."; int retval = strcat_s(str1, sizeof str1, str2); if(retval) printf("There was…
viki
  • 1
  • 1
-5
votes
1 answer

The following use of strcat_s shows "C4047: differs in levels of indirection"

What is wrong with the following lines? //Thanks to Mark #include #include int main(int argc, char* argv[]) { char datfile[127]; if(argc < 2) return -1; strcpy_s(datfile, strlen(argv[1]), argv[1]); strcat_s(datfile,…
AAK
  • 3
  • 5