Print this page
10100 Illumos is confused about calloc() arguments
   1 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
   2 /*        All Rights Reserved   */
   3 
   4 
   5 /*
   6  * Copyright (c) 1980 Regents of the University of California.
   7  * All rights reserved. The Berkeley software License Agreement
   8  * specifies the terms and conditions for redistribution.
   9  */
  10 
  11 /*
  12  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
  13  * Use is subject to license terms.
  14  */
  15 
  16 #pragma ident   "%Z%%M% %I%     %E% SMI"


  17 
  18 /*
  19  * checknr: check an nroff/troff input file for matching macro calls.
  20  * we also attempt to match size and font changes, but only the embedded
  21  * kind.  These must end in \s0 and \fP resp.  Maybe more sophistication
  22  * later but for now think of these restrictions as contributions to
  23  * structured typesetting.
  24  */
  25 #include <stdio.h>
  26 #include <stdlib.h>
  27 #include <unistd.h>
  28 #include <string.h>
  29 #include <ctype.h>
  30 #include <locale.h>
  31 
  32 #define MAXSTK  100     /* Stack size */
  33 static  int     maxstk;
  34 #define MAXBR   100     /* Max number of bracket pairs known */
  35 #define MAXCMDS 500     /* Max number of commands known */
  36 


 173                 stk = (struct stkstr *)realloc(stk,
 174                     sizeof (struct stkstr) * maxstk);
 175         }
 176 }
 177 
 178 int
 179 main(argc, argv)
 180 int argc;
 181 char **argv;
 182 {
 183         FILE *f;
 184         int i;
 185         char *cp;
 186         char b1[4];
 187 
 188         (void) setlocale(LC_ALL, "");
 189 #if !defined(TEXT_DOMAIN)
 190 #define TEXT_DOMAIN     "SYS_TEST"
 191 #endif
 192         (void) textdomain(TEXT_DOMAIN);
 193         stk = (struct stkstr *)calloc(sizeof (struct stkstr), 100);
 194         maxstk = 100;
 195         /* Figure out how many known commands there are */
 196         while (knowncmds[ncmds])
 197                 ncmds++;
 198         while (argc > 1 && argv[1][0] == '-') {
 199                 switch (argv[1][1]) {
 200 
 201                 /* -a: add pairs of macros */
 202                 case 'a':
 203                         i = strlen(argv[1]) - 2;
 204                         if (i % 6 != 0)
 205                                 usage();
 206                         /* look for empty macro slots */
 207                         for (i = 0; br[i].opbr; i++)
 208                                 ;
 209                         for (cp = argv[1]+3; cp[-1]; cp += 6) {
 210                                 br[i].opbr = malloc(3);
 211                                 (void) strncpy(br[i].opbr, cp, 2);
 212                                 br[i].clbr = malloc(3);
 213                                 (void) strncpy(br[i].clbr, cp+3, 2);


   1 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
   2 /*        All Rights Reserved   */
   3 
   4 
   5 /*
   6  * Copyright (c) 1980 Regents of the University of California.
   7  * All rights reserved. The Berkeley software License Agreement
   8  * specifies the terms and conditions for redistribution.
   9  */
  10 
  11 /*
  12  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
  13  * Use is subject to license terms.
  14  */
  15 
  16 /*
  17  * Copyright (c) 2018, Joyent, Inc.
  18  */
  19 
  20 /*
  21  * checknr: check an nroff/troff input file for matching macro calls.
  22  * we also attempt to match size and font changes, but only the embedded
  23  * kind.  These must end in \s0 and \fP resp.  Maybe more sophistication
  24  * later but for now think of these restrictions as contributions to
  25  * structured typesetting.
  26  */
  27 #include <stdio.h>
  28 #include <stdlib.h>
  29 #include <unistd.h>
  30 #include <string.h>
  31 #include <ctype.h>
  32 #include <locale.h>
  33 
  34 #define MAXSTK  100     /* Stack size */
  35 static  int     maxstk;
  36 #define MAXBR   100     /* Max number of bracket pairs known */
  37 #define MAXCMDS 500     /* Max number of commands known */
  38 


 175                 stk = (struct stkstr *)realloc(stk,
 176                     sizeof (struct stkstr) * maxstk);
 177         }
 178 }
 179 
 180 int
 181 main(argc, argv)
 182 int argc;
 183 char **argv;
 184 {
 185         FILE *f;
 186         int i;
 187         char *cp;
 188         char b1[4];
 189 
 190         (void) setlocale(LC_ALL, "");
 191 #if !defined(TEXT_DOMAIN)
 192 #define TEXT_DOMAIN     "SYS_TEST"
 193 #endif
 194         (void) textdomain(TEXT_DOMAIN);
 195         stk = (struct stkstr *)calloc(100, sizeof (struct stkstr));
 196         maxstk = 100;
 197         /* Figure out how many known commands there are */
 198         while (knowncmds[ncmds])
 199                 ncmds++;
 200         while (argc > 1 && argv[1][0] == '-') {
 201                 switch (argv[1][1]) {
 202 
 203                 /* -a: add pairs of macros */
 204                 case 'a':
 205                         i = strlen(argv[1]) - 2;
 206                         if (i % 6 != 0)
 207                                 usage();
 208                         /* look for empty macro slots */
 209                         for (i = 0; br[i].opbr; i++)
 210                                 ;
 211                         for (cp = argv[1]+3; cp[-1]; cp += 6) {
 212                                 br[i].opbr = malloc(3);
 213                                 (void) strncpy(br[i].opbr, cp, 2);
 214                                 br[i].clbr = malloc(3);
 215                                 (void) strncpy(br[i].clbr, cp+3, 2);