Changeset 107 in libcf


Ignore:
Timestamp:
05/30/13 16:57:55 (11 years ago)
Author:
cheese
Message:

#1 change sprintf to snprintf and imporve performance of log

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/cf_debug.c

    r87 r107  
    225225
    226226    /* push to callstack */
    227     sprintf (push->file, "%s", file);
    228     sprintf (push->func, "%s", func);
     227    snprintf (push->file, NAME_LENGTH, "%s", file);
     228    snprintf (push->func, NAME_LENGTH, "%s", func);
    229229    push->line = line;
    230230    push->caller = context->callstack.caller;
     
    260260    if (callstack != NULL)
    261261    {
    262         sprintf (callstack->file    , "%s", pop->file);
    263         sprintf (callstack->function, "%s", pop->func);
     262        snprintf (callstack->file    , NAME_LENGTH, "%s", pop->file);
     263        snprintf (callstack->function, NAME_LENGTH, "%s", pop->func);
    264264        callstack->line = pop->line;
    265265    }
  • trunk/src/cf_log.c

    r103 r107  
    307307                 va_list    valist)
    308308{
     309#define BUF_LEN 16 * 1024
    309310    CF_LOG_CTX  * context = (CF_LOG_CTX *) ctx;
    310311//  va_list     valist;
    311     char        buffer[16 * 1024] = {0x00,};
     312    char        buffer[BUF_LEN + 1] = {0x00,};
    312313    char        datetime[LOG_DATETIME_LENGTH + 1] = {0x00,};
     314    int         length = 0;
    313315
    314316    ASSERT_CTX (ctx);
     
    318320
    319321    CF_Log_Local_GetTimeString (datetime);
    320     snprintf (buffer, sizeof (buffer) - 1, "[%s][%s] ", datetime, prefix);
    321     vsprintf (buffer + strlen (buffer), fmt, valist);
     322    length = snprintf (buffer, BUF_LEN, "[%s][%s] ", datetime, prefix);
     323    vsnprintf (&buffer[length], BUF_LEN - (size_t)length, fmt, valist);
    322324
    323325    CF_Log_Local_Push (context, buffer, strlen (buffer));
Note: See TracChangeset for help on using the changeset viewer.