Buffer probs

This is a discussion on Buffer probs within the C++ Programming forums, part of the General Programming Boards category; This call: Code: strncpy(entry_buf, strstr(file_buf, sought_buf), MAX_ENTRY_LEN); Would that fail in any way if one of the buffers are empty? ...

  1. #1
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709

    Buffer probs

    This call:

    Code:
    strncpy(entry_buf, strstr(file_buf, sought_buf), MAX_ENTRY_LEN);
    Would that fail in any way if one of the buffers are empty? I get a runtime error (the infamour XP runtime error dialog).
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,437
    Well if strstr() doesn't find anything, then you're in doo-doo because it returns a NULL pointer.
    Plus strncpy() doesn't always append a \0 to the string, so if you're assuming that as well, then that could be another problem.

    Assuming of course that you've allocated the amount of space you say you have.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 10-29-2006, 04:04 AM
  2. writing a pack-style function, any advices?
    By isaac_s in forum C Programming
    Replies: 10
    Last Post: 07-08-2006, 08:09 PM
  3. buffer contents swapping
    By daluu in forum C++ Programming
    Replies: 7
    Last Post: 10-14-2004, 02:34 PM
  4. Tetris Questions
    By KneeGrow in forum Game Programming
    Replies: 19
    Last Post: 10-28-2003, 10:12 PM
  5. Console Screen Buffer
    By GaPe in forum Windows Programming
    Replies: 0
    Last Post: 02-06-2003, 04:15 AM

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