err() on allocation failure. WARNS=9 compliant

use #if 0, #ifndef lint, #endif /* not lint */, #endif ordering
when a message is provided, use errx() instead of err().
This commit is contained in:
Philippe Charnier 2003-06-15 09:28:17 +00:00
parent 872e095cc6
commit d005495293
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=116390
7 changed files with 46 additions and 21 deletions

View File

@ -33,11 +33,12 @@
* SUCH DAMAGE.
*/
#ifndef lint
#if 0
#ifndef lint
static char sccsid[] = "@(#)args.c 8.1 (Berkeley) 6/6/93";
#endif
#endif /* not lint */
#endif
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
@ -81,7 +82,7 @@ const char *option_source = "?";
* default value is the one actually assigned.
*/
struct pro {
const char *p_name; /* name, eg -bl, -cli */
const char *p_name; /* name, e.g. -bl, -cli */
int p_type; /* type (int, bool, special) */
int p_default; /* the default value (if int) */
int p_special; /* depends on type */
@ -268,6 +269,8 @@ set_option(char *arg)
goto need_param;
{
char *str = (char *) malloc(strlen(param_start) + 1);
if (str == NULL)
err(1, NULL);
strcpy(str, param_start);
addkey(str, 4);
}

View File

@ -41,11 +41,12 @@ static const char copyright[] =
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
#if 0
#ifndef lint
static char sccsid[] = "@(#)indent.c 5.17 (Berkeley) 6/7/93";
#endif
#endif /* not lint */
#endif
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
@ -69,11 +70,12 @@ const char *out_name = "Standard Output"; /* will always point to name
* of output file */
char bakfile[MAXPATHLEN] = "";
extern int found_err; /* flag set in diagN() on error */
int
main(int argc, char **argv)
{
extern int found_err; /* flag set in diagN() on error */
int dec_ind; /* current indentation for declarations */
int di_stack[20]; /* a stack of structure indentation levels */
int flushed_nl; /* used when buffering up comments to remember
@ -99,15 +101,24 @@ main(int argc, char **argv)
| INITIALIZATION |
\*-----------------------------------------------*/
found_err = 0;
ps.p_stack[0] = stmt; /* this is the parser's stack */
ps.last_nl = true; /* this is true if the last thing scanned was
* a newline */
ps.last_token = semicolon;
combuf = (char *) malloc(bufsize);
if (combuf == NULL)
err(1, NULL);
labbuf = (char *) malloc(bufsize);
if (labbuf == NULL)
err(1, NULL);
codebuf = (char *) malloc(bufsize);
if (codebuf == NULL)
err(1, NULL);
tokenbuf = (char *) malloc(bufsize);
if (tokenbuf == NULL)
err(1, NULL);
l_com = combuf + bufsize - 5;
l_lab = labbuf + bufsize - 5;
l_code = codebuf + bufsize - 5;
@ -122,6 +133,8 @@ main(int argc, char **argv)
s_token = e_token = tokenbuf + 1;
in_buffer = (char *) malloc(10);
if (in_buffer == NULL)
err(1, NULL);
in_buffer_limit = in_buffer + 8;
buf_ptr = buf_end = in_buffer;
line_no = 1;
@ -133,7 +146,6 @@ main(int argc, char **argv)
di_stack[ps.dec_nest = 0] = 0;
ps.want_blank = ps.in_stmt = ps.ind_stmt = false;
scase = ps.pcase = false;
squest = 0;
sc_end = 0;
@ -142,8 +154,6 @@ main(int argc, char **argv)
output = 0;
/*--------------------------------------------------*\
| COMMAND LINE SCAN |
\*--------------------------------------------------*/
@ -349,7 +359,7 @@ main(int argc, char **argv)
if (sc_end >= &(save_com[sc_size])) { /* check for temp buffer
* overflow */
diag2(1, "Internal buffer overflow - Move big comment from right after if, while, or whatever.");
diag2(1, "Internal buffer overflow - Move big comment from right after if, while, or whatever");
fflush(output);
exit(1);
}
@ -419,7 +429,7 @@ main(int argc, char **argv)
|| s_com != e_com) /* must dump end of line */
dump_line();
if (ps.tos > 1) /* check for balanced braces */
diag2(1, "Stuff missing from end of file.");
diag2(1, "Stuff missing from end of file");
if (verbose) {
printf("There were %d output lines and %d comments\n",
@ -1104,7 +1114,7 @@ main(int argc, char **argv)
*/
if (match_state[ifdef_level].tos >= 0
&& bcmp(&ps, &match_state[ifdef_level], sizeof ps))
diag2(0, "Syntactically inconsistent #ifdef alternatives.");
diag2(0, "Syntactically inconsistent #ifdef alternatives");
#endif
}
if (blanklines_around_conditional_compilation) {

View File

@ -58,6 +58,8 @@ FILE *output; /* the output file */
if (e_code >= l_code) { \
int nsize = l_code-s_code+400; \
codebuf = (char *) realloc(codebuf, nsize); \
if (codebuf == NULL) \
err(1, NULL); \
e_code = codebuf + (e_code-s_code) + 1; \
l_code = codebuf + nsize - 5; \
s_code = codebuf + 1; \
@ -66,6 +68,8 @@ FILE *output; /* the output file */
if (e_com >= l_com) { \
int nsize = l_com-s_com+400; \
combuf = (char *) realloc(combuf, nsize); \
if (combuf == NULL) \
err(1, NULL); \
e_com = combuf + (e_com-s_com) + 1; \
l_com = combuf + nsize - 5; \
s_com = combuf + 1; \
@ -74,6 +78,8 @@ FILE *output; /* the output file */
if (e_lab >= l_lab) { \
int nsize = l_lab-s_lab+400; \
labbuf = (char *) realloc(labbuf, nsize); \
if (labbuf == NULL) \
err(1, NULL); \
e_lab = labbuf + (e_lab-s_lab) + 1; \
l_lab = labbuf + nsize - 5; \
s_lab = labbuf + 1; \
@ -82,6 +88,8 @@ FILE *output; /* the output file */
if (e_token >= l_token) { \
int nsize = l_token-s_token+400; \
tokenbuf = (char *) realloc(tokenbuf, nsize); \
if (tokenbuf == NULL) \
err(1, NULL); \
e_token = tokenbuf + (e_token-s_token) + 1; \
l_token = tokenbuf + nsize - 5; \
s_token = tokenbuf + 1; \

View File

@ -33,11 +33,12 @@
* SUCH DAMAGE.
*/
#ifndef lint
#if 0
#ifndef lint
static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 6/6/93";
#endif
#endif /* not lint */
#endif
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
@ -358,8 +359,8 @@ fill_buffer(void)
int size = (in_buffer_limit - in_buffer) * 2 + 10;
int offset = p - in_buffer;
in_buffer = realloc(in_buffer, size);
if (in_buffer == 0)
err(1, "input line too long");
if (in_buffer == NULL)
errx(1, "input line too long");
p = in_buffer + offset;
in_buffer_limit = in_buffer + size - 2;
}

View File

@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$");
* of token scanned.
*/
#include <err.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
@ -58,8 +59,6 @@ __FBSDID("$FreeBSD$");
#define alphanum 1
#define opchar 3
void fill_buffer(void);
struct templ {
const char *rwd;
int rwcode;

View File

@ -32,11 +32,13 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if 0
#ifndef lint
static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */
#endif
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
@ -168,7 +170,7 @@ parse(int tk) /* tk: the code for the construct scanned */
ps.p_stack[ps.tos] = stmt;
}
else
diag2(1, "Statement nesting error.");
diag2(1, "Statement nesting error");
break;
case swstmt: /* had switch (...) */

View File

@ -33,14 +33,16 @@
* SUCH DAMAGE.
*/
#ifndef lint
#if 0
#ifndef lint
static char sccsid[] = "@(#)pr_comment.c 8.1 (Berkeley) 6/6/93";
#endif
#endif /* not lint */
#endif
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include "indent_globs.h"