Changeset 1634


Ignore:
Timestamp:
02/20/10 15:40:38 (11 years ago)
Author:
merek
Message:

Reintroducing cs_strncpy()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/oscam-simples.c

    r1584 r1634  
    359359}
    360360#endif
     361
     362/*
     363* Ordinary strncpy does not terminate the string if the source
     364* is exactly as long or longer as the specified size. This can raise security issues.
     365* This function is a replacement which makes sure that a \0 is always added.
     366* num should be the real size of char array (do not subtract -1).
     367*/
     368void cs_strncpy(char * destination, const char * source, size_t num){
     369        uint32 l, size = strlen(source);
     370        if(size > num - 1) l = num - 1;
     371        else l = size;
     372        memcpy(destination, source, l);
     373        destination[l] = '\0';
     374}
Note: See TracChangeset for help on using the changeset viewer.