Strcpy

This is a discussion on Strcpy within the C Programming forums, part of the General Programming Boards category; Originally Posted by MacGyver Again, I ask, why not just dynamically size your buffer for sprintf() or properly size the ...

  1. #16
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,272
    Quote Originally Posted by MacGyver View Post
    Again, I ask, why not just dynamically size your buffer for sprintf() or properly size the static buffers to eliminate the chance of a buffer overflow? Why run a risk of cutting off part of your message?
    if the consequences of that happening are not severe it might be worth the simplicity.

  2. #17
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by MacGyver View Post
    There's no possibility to overwrite your buffer if you use it right.
    The key part here being "if you use it right".
    I think the n string functions make it harder (but obviously not impossible) to "use it wrong".

    brewbuck:
    Is snprintf() a standard C function? I've never heard of it and I don't see it listed on this site: http://www.cppreference.com/all_c_functions.html
    Is it a C99 function?

  3. #18
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,272
    Quote Originally Posted by cpjust View Post
    The key part here being "if you use it right".
    I think the n string functions make it harder (but obviously not impossible) to "use it wrong".

    brewbuck:
    Is snprintf() a standard C function? I've never heard of it and I don't see it listed on this site: http://www.cppreference.com/all_c_functions.html
    Is it a C99 function?
    Yes, it is C99. I so often forget.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A Full Program to analyze.
    By sergioms in forum C Programming
    Replies: 2
    Last Post: 12-30-2008, 09:42 AM
  2. Using strcpy() and arrays of structs
    By vital101 in forum C Programming
    Replies: 3
    Last Post: 04-26-2007, 10:04 PM
  3. Where is strcpy() defined? (Can't find in string.h ect)
    By Zero_Point in forum C++ Programming
    Replies: 6
    Last Post: 04-03-2006, 06:14 PM
  4. Question about strcpy
    By Kevinmun in forum C Programming
    Replies: 4
    Last Post: 11-02-2005, 11:00 PM
  5. strcpy
    By Luigi in forum C++ Programming
    Replies: 17
    Last Post: 02-16-2003, 04:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21