Bobby Hicks:  "strncmp uses a 3rd argument so that when it's comparing, it
won't go over the 3rd arg so that there is no buffer overflowing."

That's silly.  They preform relatively different operations.  The function
strncmp() returns a positive integer if, within the first n bytes of string
s1 and string s2, string s1 is lexically greater than string s2; zero if the
first n bytes of the two strings are identical; and a negative integer if
with the first n bytes string s1 is lexically less than string s2. The
function strcmp() returns a positive integer if string s1 is lexically
greater than string s2; zero if the two strings are identical; and a
negative integer if string s1 is lexically less than string s2.

It's more likely (to me) to make strncmp buffer overflow, if you define N to
be larger than one of the string sizes.  Perhaps there's checked for this; I
don't know.   Strcmp wouldn't buffer overflow.  It's the difference between
arrays a[40] and a[], and writing to the 41st (42nd, technically) element.
a[40] and a[] would be strncmp and strcmp, respectively.

Maybe I'm talking out of my ass here.  Probably.

Jeremy Hill
"Evangelion"
Shards of Eternity

---
SYNOPSIS
#include <string.h>
int strncmp(const char *s1, const char *s2, size_t n);

DESCRIPTION
The strncmp() function makes a comparison of not more than n characters
between the array pointed to by s1 and the array pointed to by s2.
Characters that follow a null character are not compared. The function
strcmp() returns a positive integer if string s1 is lexically greater than
string s2; zero if the two strings are identical; and a negative integer if
string s1 is lexically less than string s2.




PARAMETERS
  s1
Points to an array of characters terminated by a null character.
  s2
Points to a second array of characters terminated by a null character.
  n
Specifies the maximum number of characters to compare.

RETURN VALUES
The function strncmp() returns a positive integer if, within the first n byt
es of string s1 and string s2, string s1 is lexically greater than string
s2; zero if the first n bytes of the two strings are identical; and a
negative integer if with the first n bytes string s1 is lexically less than
string s2.
----------------------------------------------
SYNOPSIS
#include <string.h>
int strcmp(const char *s1, const char *s2);

DESCRIPTION
The strcmp() function compares the string pointed to by s1 to the string
pointed to by s2.

PARAMETERS
  s1
Points to a null-terminated string to compare.
  s2
Points to a null=terminated string to compare.

RETURN VALUES
The function strcmp() returns a positive integer if string s1 is lexically
greater than string s2; zero if the two strings are identical; and a
negative integer if string s1 is lexically less than string s2.





Reply via email to