Changeset e3a75ed


Ignore:
Timestamp:
Mar 5, 2011, 3:25:29 PM (14 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.10, 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.
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • functions.c

    r010a951 re3a75ed  
    22582258  const owl_filter *f;
    22592259  const owl_list *fl;
    2260   char buff[5000];
    22612260  char *tmp;
    22622261  owl_fmtext fm;
     
    22712270  for (i=0; i<j; i++) {
    22722271    f=owl_list_get_element(fl, i);
    2273     snprintf(buff, sizeof(buff), "[% 2d] ", i+1);
    2274     owl_fmtext_append_normal(&fm, buff);
     2272    owl_fmtext_appendf_normal(&fm, "[% 2d] ", i+1);
    22752273    tmp = owl_filter_print(f);
    22762274    owl_fmtext_append_normal(&fm, tmp);
  • 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
  • zephyr.c

    rbb85767 re3a75ed  
    762762    }
    763763  } else if (!strcmp(retnotice->z_message, ZSRVACK_NOTSENT)) {
    764     #define BUFFLEN 1024
    765764    if (retnotice->z_recipient == NULL
    766765        || *retnotice->z_recipient == 0
    767766        || *retnotice->z_recipient == '@') {
    768       char buff[BUFFLEN];
     767      char *buff;
    769768      owl_function_error("No one subscribed to class %s", retnotice->z_class);
    770       snprintf(buff, BUFFLEN, "Could not send message to class %s: no one subscribed.\n", retnotice->z_class);
     769      buff = g_strdup_printf("Could not send message to class %s: no one subscribed.\n", retnotice->z_class);
    771770      owl_function_adminmsg("", buff);
     771      g_free(buff);
    772772    } else {
    773       char buff[BUFFLEN];
     773      char *buff;
    774774      owl_zwrite zw;
    775775      char *realm;
     
    783783       */
    784784      if(strcasecmp(retnotice->z_class, "message")) {
    785         snprintf(buff, BUFFLEN,
     785        buff = g_strdup_printf(
    786786                 "Could not send message to %s: "
    787787                 "not logged in or subscribing to class %s, instance %s.\n",
     
    790790                 retnotice->z_class_inst);
    791791      } else if(strcasecmp(retnotice->z_class_inst, "personal")) {
    792         snprintf(buff, BUFFLEN,
     792        buff = g_strdup_printf(
    793793                 "Could not send message to %s: "
    794794                 "not logged in or subscribing to instance %s.\n",
     
    796796                 retnotice->z_class_inst);
    797797      } else {
    798         snprintf(buff, BUFFLEN,
     798        buff = g_strdup_printf(
    799799                 "Could not send message to %s: "
    800800                 "not logged in or subscribing to messages.\n",
     
    820820
    821821      owl_zwrite_cleanup(&zw);
     822      g_free(buff);
    822823      g_free(tmp);
    823824    }
Note: See TracChangeset for help on using the changeset viewer.