Logo Search packages:      
Sourcecode: likewise-open version File versions

char* safe_strcat_fn ( const char *  fn,
int  line,
char *  dest,
const char *  src,
size_t  maxlength 
)

Safe string cat into a string. maxlength does not include the terminating zero.

Definition at line 722 of file util_str.c.

{
      size_t src_len, dest_len;

      if (!dest) {
            DEBUG(0,("ERROR: NULL dest in safe_strcat, "
                  "called from [%s][%d]\n", fn, line));
            return NULL;
      }

      if (!src)
            return dest;

      src_len = strnlen(src, maxlength + 1);
      dest_len = strnlen(dest, maxlength + 1);

#ifdef DEVELOPER
      clobber_region(fn, line, dest + dest_len, maxlength + 1 - dest_len);
#endif

      if (src_len + dest_len > maxlength) {
            DEBUG(0,("ERROR: string overflow by %d "
                  "in safe_strcat [%.50s]\n",
                   (int)(src_len + dest_len - maxlength), src));
            if (maxlength > dest_len) {
                  memcpy(&dest[dest_len], src, maxlength - dest_len);
            }
            dest[maxlength] = 0;
            return NULL;
      }

      memcpy(&dest[dest_len], src, src_len);
      dest[dest_len + src_len] = 0;
      return dest;
}


Generated by  Doxygen 1.6.0   Back to index