]> skyeroc.xyz Git - dgamelaunch/commitdiff
* Message length is at most 80, not 79 characters
authorJilles Tjoelker <jilles@stack.nl>
Sun, 22 Feb 2004 22:40:33 +0000 (22:40 +0000)
committerJilles Tjoelker <jilles@stack.nl>
Sun, 22 Feb 2004 22:40:33 +0000 (22:40 +0000)
* Improve dgl-wall's handling of bad arguments

git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@254 db0b04b0-f4d1-0310-9a6d-de3e77497b0e

dgamelaunch.c
dgl-wall.c

index 4e1d555ea89f55eeca2a27a88318f045b8f42a0f..b98374d2b555fbb1f254a307798fc9efda9b982c 100644 (file)
@@ -511,7 +511,7 @@ void
 domailuser (char *username)
 {
   unsigned int len, i;
-  char *spool_fn, message[80];
+  char *spool_fn, message[81];
   FILE *user_spool = NULL;
   time_t now;
   int mail_empty = 1;
index 57aa73e37afc32ac4c1c3d7df97356aa6f117754..0888fe32d3f0bb5deff0e740b5b008cecbcec0f0 100644 (file)
@@ -18,7 +18,7 @@ int
 main (int argc, char** argv)
 {
   int c, i, len;
-  char buf[80], *ptr = buf, *from = NULL;
+  char buf[82], *ptr = buf, *from = NULL;
   struct dg_game ** games = NULL;
   struct flock fl = { 0 };
   struct passwd* pw = getpwuid(getuid());
@@ -41,6 +41,8 @@ main (int argc, char** argv)
       case 'F':
        from = strdup(optarg);
        break;
+      default:
+       goto usage;
     }
   }
   
@@ -49,19 +51,20 @@ main (int argc, char** argv)
 
   while (optind < argc)
   {
-    if (strlen(buf) >= 80)
-    {
-      fprintf(stderr, "Error: Message is too long! (80 chars max)\n");
-      return 1;
-    }
-    else if (strlen(buf) != 0)
-      strlcat (buf, " ", 80);
-    strlcat (buf, argv[optind++], 80);
+    if (strlen(buf) != 0)
+      strlcat (buf, " ", sizeof(buf));
+    strlcat (buf, argv[optind++], sizeof(buf));
+  }
+  if (strlen(buf) > 80)
+  {
+    fprintf(stderr, "Error: Message is too long! (80 chars max)\n");
+    return 1;
   }
 
   if (strlen(buf) == 0)
   {
-    fprintf(stderr, "Error: no message?\n");
+usage:
+    fprintf(stderr, "Usage: %s [-f config] [-F fromname] message\n", argv[0]);
     return 1;
   }