Changeset e3a75ed for logging.c


Ignore:
Timestamp:
Mar 5, 2011, 3:25:29 PM (10 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.8, release-1.9
Children:
488913a
Parents:
010a951
git-author:
David Benjamin <davidben@mit.edu> (02/28/11 18:45:28)
git-committer:
David Benjamin <davidben@mit.edu> (03/05/11 15:25:29)
Message:
Replace the remaining snprintfs with g_strdup_printf

Hard-coded buffer sizes are silly.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • logging.c

    r60d7935 re3a75ed  
    126126void owl_log_outgoing(const owl_message *m)
    127127{
    128   char filename[MAXPATHLEN], *logpath;
     128  char *filename, *logpath;
    129129  char *to, *temp;
    130130  GList *cc;
     
    139139    while (cc != NULL) {
    140140      temp = short_zuser(cc->data);
    141       snprintf(filename, MAXPATHLEN, "%s/%s", logpath, temp);
     141      filename = g_strdup_printf("%s/%s", logpath, temp);
    142142      owl_log_append(m, filename);
    143143
     144      g_free(filename);
    144145      g_free(temp);
    145146      g_free(cc->data);
     
    162163  }
    163164
    164   snprintf(filename, MAXPATHLEN, "%s/%s", logpath, to);
     165  filename = g_strdup_printf("%s/%s", logpath, to);
    165166  owl_log_append(m, filename);
    166167  g_free(to);
    167 
    168   snprintf(filename, MAXPATHLEN, "%s/all", logpath);
     168  g_free(filename);
     169
     170  filename = g_strdup_printf("%s/all", logpath);
    169171  owl_log_append(m, filename);
    170172  g_free(logpath);
     173  g_free(filename);
    171174}
    172175
     
    175178{
    176179  FILE *file;
    177   char filename[MAXPATHLEN], *logpath;
     180  char *filename, *logpath;
    178181  char *tobuff;
    179182  owl_message *m;
     
    196199  logpath = owl_util_makepath(owl_global_get_logpath(&g));
    197200
    198   snprintf(filename, MAXPATHLEN, "%s/%s", logpath, tobuff);
     201  filename = g_strdup_printf("%s/%s", logpath, tobuff);
    199202  file=fopen(filename, "a");
     203  g_free(filename);
    200204  if (!file) {
    201205    owl_function_error("Unable to open file for outgoing logging");
     
    210214  fclose(file);
    211215
    212   snprintf(filename, MAXPATHLEN, "%s/all", logpath);
     216  filename = g_strdup_printf("%s/all", logpath);
    213217  g_free(logpath);
    214218  file=fopen(filename, "a");
     219  g_free(filename);
    215220  if (!file) {
    216221    owl_function_error("Unable to open file for outgoing logging");
     
    229234void owl_log_incoming(const owl_message *m)
    230235{
    231   char filename[MAXPATHLEN], allfilename[MAXPATHLEN], *logpath;
     236  char *filename, *allfilename, *logpath;
    232237  const char *from=NULL;
    233238  char *frombuff=NULL;
     
    311316  if (personal) {
    312317    logpath = owl_util_makepath(owl_global_get_logpath(&g));
    313     snprintf(filename, MAXPATHLEN, "%s/%s", logpath, from);
    314     snprintf(allfilename, MAXPATHLEN, "%s/all", logpath);
     318    filename = g_strdup_printf("%s/%s", logpath, from);
     319    allfilename = g_strdup_printf("%s/all", logpath);
    315320    owl_log_append(m, allfilename);
    316 
     321    g_free(allfilename);
    317322  } else {
    318323    logpath = owl_util_makepath(owl_global_get_classlogpath(&g));
    319     snprintf(filename, MAXPATHLEN, "%s/%s", logpath, from);
     324    filename = g_strdup_printf("%s/%s", logpath, from);
    320325  }
    321326
    322327  owl_log_append(m, filename);
     328  g_free(filename);
    323329
    324330  if (personal && owl_message_is_type_zephyr(m)) {
     
    332338      temp = short_zuser(cc->data);
    333339      if (strcasecmp(temp, frombuff) != 0) {
    334         snprintf(filename, MAXPATHLEN, "%s/%s", logpath, temp);
     340        filename = g_strdup_printf("%s/%s", logpath, temp);
    335341        owl_log_append(m, filename);
     342        g_free(filename);
    336343      }
    337344
Note: See TracChangeset for help on using the changeset viewer.