aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard M. Stallman1994-12-04 20:59:04 +0000
committerRichard M. Stallman1994-12-04 20:59:04 +0000
commitdf6530f8da94ae4f3a3fc0f96f6526a2237e900b (patch)
treeafb7e5a59616cc8673df94491f8facd50c138be3 /src
parentc4b55ff15ce75f960dc1bd76475cbabe4face0b1 (diff)
downloademacs-df6530f8da94ae4f3a3fc0f96f6526a2237e900b.tar.gz
emacs-df6530f8da94ae4f3a3fc0f96f6526a2237e900b.zip
(argmatch): Take argc as arg; don't go past end of argv.
(main): Change calls to argmatch.
Diffstat (limited to 'src')
-rw-r--r--src/emacs.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/src/emacs.c b/src/emacs.c
index a2ac89a9b23..34554d157f5 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -349,8 +349,9 @@ __main ()
349 enough information to do it right. */ 349 enough information to do it right. */
350 350
351static int 351static int
352argmatch (argv, sstr, lstr, minlen, valptr, skipptr) 352argmatch (argv, argc, sstr, lstr, minlen, valptr, skipptr)
353 char **argv; 353 char **argv;
354 int argc;
354 char *sstr; 355 char *sstr;
355 char *lstr; 356 char *lstr;
356 int minlen; 357 int minlen;
@@ -359,7 +360,13 @@ argmatch (argv, sstr, lstr, minlen, valptr, skipptr)
359{ 360{
360 char *p; 361 char *p;
361 int arglen; 362 int arglen;
362 char *arg = argv[*skipptr+1]; 363 char *arg;
364
365 /* Don't access argv[argc]; give up in advance. */
366 if (argc <= *skipptr + 1)
367 return 0;
368
369 arg = argv[*skipptr+1];
363 if (arg == NULL) 370 if (arg == NULL)
364 return 0; 371 return 0;
365 if (strcmp (arg, sstr) == 0) 372 if (strcmp (arg, sstr) == 0)
@@ -415,7 +422,7 @@ main (argc, argv, envp)
415 422
416/* Map in shared memory, if we are using that. */ 423/* Map in shared memory, if we are using that. */
417#ifdef HAVE_SHM 424#ifdef HAVE_SHM
418 if (argmatch (argv, "-nl", "--no-shared-memory", 6, NULL, &skip_args)) 425 if (argmatch (argv, argc, "-nl", "--no-shared-memory", 6, NULL, &skip_args))
419 { 426 {
420 map_in_data (0); 427 map_in_data (0);
421 /* The shared memory was just restored, which clobbered this. */ 428 /* The shared memory was just restored, which clobbered this. */
@@ -442,7 +449,7 @@ main (argc, argv, envp)
442 /* If -map specified, map the data file in */ 449 /* If -map specified, map the data file in */
443 { 450 {
444 char *file; 451 char *file;
445 if (argmatch (argv, "-map", "--map-data", 3, &mapin_file, &skip_args)) 452 if (argmatch (argv, argc, "-map", "--map-data", 3, &mapin_file, &skip_args))
446 mapin_data (file); 453 mapin_data (file);
447 } 454 }
448 455
@@ -521,7 +528,7 @@ main (argc, argv, envp)
521 /* Handle the -t switch, which specifies filename to use as terminal */ 528 /* Handle the -t switch, which specifies filename to use as terminal */
522 { 529 {
523 char *term; 530 char *term;
524 if (argmatch (argv, "-t", "--terminal", 4, &term, &skip_args)) 531 if (argmatch (argv, argc, "-t", "--terminal", 4, &term, &skip_args))
525 { 532 {
526 int result; 533 int result;
527 close (0); 534 close (0);
@@ -545,16 +552,16 @@ main (argc, argv, envp)
545#endif 552#endif
546 } 553 }
547 } 554 }
548 if (argmatch (argv, "-nw", "--no-windows", 6, NULL, &skip_args)) 555 if (argmatch (argv, argc, "-nw", "--no-windows", 6, NULL, &skip_args))
549 inhibit_window_system = 1; 556 inhibit_window_system = 1;
550 557
551 /* Handle the -batch switch, which means don't do interactive display. */ 558 /* Handle the -batch switch, which means don't do interactive display. */
552 noninteractive = 0; 559 noninteractive = 0;
553 if (argmatch (argv, "-batch", "--batch", 5, NULL, &skip_args)) 560 if (argmatch (argv, argc, "-batch", "--batch", 5, NULL, &skip_args))
554 noninteractive = 1; 561 noninteractive = 1;
555 562
556 /* Handle the --help option, which gives a usage message.. */ 563 /* Handle the --help option, which gives a usage message.. */
557 if (argmatch (argv, "-help", "--help", 3, NULL, &skip_args)) 564 if (argmatch (argv, argc, "-help", "--help", 3, NULL, &skip_args))
558 { 565 {
559 printf ("\ 566 printf ("\
560Usage: %s [-t term] [--terminal term] [-nw] [--no-windows] [--batch]\n\ 567Usage: %s [-t term] [--terminal term] [-nw] [--no-windows] [--batch]\n\
@@ -575,9 +582,9 @@ Usage: %s [-t term] [--terminal term] [-nw] [--no-windows] [--batch]\n\
575 int i; 582 int i;
576 int count_before = skip_args; 583 int count_before = skip_args;
577 584
578 if (argmatch (argv, "-d", "--display", 3, &displayname, &skip_args)) 585 if (argmatch (argv, argc, "-d", "--display", 3, &displayname, &skip_args))
579 display_arg = 1; 586 display_arg = 1;
580 else if (argmatch (argv, "-display", 0, 3, &displayname, &skip_args)) 587 else if (argmatch (argv, argc, "-display", 0, 3, &displayname, &skip_args))
581 display_arg = 1; 588 display_arg = 1;
582 589
583 /* If we have the form --display=NAME, 590 /* If we have the form --display=NAME,
@@ -849,12 +856,12 @@ Usage: %s [-t term] [--terminal term] [-nw] [--no-windows] [--batch]\n\
849 { 856 {
850 char *file; 857 char *file;
851 /* Handle -l loadup-and-dump, args passed by Makefile. */ 858 /* Handle -l loadup-and-dump, args passed by Makefile. */
852 if (argmatch (argv, "-l", "--load", 3, &file, &skip_args)) 859 if (argmatch (argv, argc, "-l", "--load", 3, &file, &skip_args))
853 Vtop_level = Fcons (intern ("load"), 860 Vtop_level = Fcons (intern ("load"),
854 Fcons (build_string (file), Qnil)); 861 Fcons (build_string (file), Qnil));
855#ifdef CANNOT_DUMP 862#ifdef CANNOT_DUMP
856 /* Unless next switch is -nl, load "loadup.el" first thing. */ 863 /* Unless next switch is -nl, load "loadup.el" first thing. */
857 if (!argmatch (argv, "-nl", "--no-loadup", 6, NULL, &skip_args)) 864 if (!argmatch (argv, argc, "-nl", "--no-loadup", 6, NULL, &skip_args))
858 Vtop_level = Fcons (intern ("load"), 865 Vtop_level = Fcons (intern ("load"),
859 Fcons (build_string ("loadup.el"), Qnil)); 866 Fcons (build_string ("loadup.el"), Qnil));
860#endif /* CANNOT_DUMP */ 867#endif /* CANNOT_DUMP */
@@ -872,7 +879,7 @@ Usage: %s [-t term] [--terminal term] [-nw] [--no-windows] [--batch]\n\
872#endif /* defined (sun) || defined (LOCALTIME_CACHE) */ 879#endif /* defined (sun) || defined (LOCALTIME_CACHE) */
873 880
874 /* Handle the GNU standard option --version. */ 881 /* Handle the GNU standard option --version. */
875 if (argmatch (argv, "-version", "--version", 3, NULL, &skip_args)) 882 if (argmatch (argv, argc, "-version", "--version", 3, NULL, &skip_args))
876 { 883 {
877 Lisp_Object ver; 884 Lisp_Object ver;
878 ver = call0 (intern ("emacs-version")); 885 ver = call0 (intern ("emacs-version"));