summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorcharnier <charnier@FreeBSD.org>2003-06-15 09:28:17 +0000
committercharnier <charnier@FreeBSD.org>2003-06-15 09:28:17 +0000
commitd46a4b84c36ffc40eac467a205717414ef8311c0 (patch)
tree8b645c361f8cd29562d33fc7a6cd5e073458ffaa /usr.bin
parent7b4b7a670b84034ab40c33b9bdda786293e36dfe (diff)
downloadFreeBSD-src-d46a4b84c36ffc40eac467a205717414ef8311c0.zip
FreeBSD-src-d46a4b84c36ffc40eac467a205717414ef8311c0.tar.gz
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().
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/indent/args.c9
-rw-r--r--usr.bin/indent/indent.c28
-rw-r--r--usr.bin/indent/indent_globs.h8
-rw-r--r--usr.bin/indent/io.c9
-rw-r--r--usr.bin/indent/lexi.c3
-rw-r--r--usr.bin/indent/parse.c4
-rw-r--r--usr.bin/indent/pr_comment.c6
7 files changed, 46 insertions, 21 deletions
diff --git a/usr.bin/indent/args.c b/usr.bin/indent/args.c
index 7998fc7..a8c4f9f 100644
--- a/usr.bin/indent/args.c
+++ b/usr.bin/indent/args.c
@@ -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 @@ found:
goto need_param;
{
char *str = (char *) malloc(strlen(param_start) + 1);
+ if (str == NULL)
+ err(1, NULL);
strcpy(str, param_start);
addkey(str, 4);
}
diff --git a/usr.bin/indent/indent.c b/usr.bin/indent/indent.c
index d903cbb..5f97f03 100644
--- a/usr.bin/indent/indent.c
+++ b/usr.bin/indent/indent.c
@@ -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 @@ check_type:
|| 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 @@ check_type:
*/
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) {
diff --git a/usr.bin/indent/indent_globs.h b/usr.bin/indent/indent_globs.h
index 9f319e0..c189bfd 100644
--- a/usr.bin/indent/indent_globs.h
+++ b/usr.bin/indent/indent_globs.h
@@ -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; \
diff --git a/usr.bin/indent/io.c b/usr.bin/indent/io.c
index d1bfcf3..7af2d19 100644
--- a/usr.bin/indent/io.c
+++ b/usr.bin/indent/io.c
@@ -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;
}
diff --git a/usr.bin/indent/lexi.c b/usr.bin/indent/lexi.c
index 15c2fea..c716bc8 100644
--- a/usr.bin/indent/lexi.c
+++ b/usr.bin/indent/lexi.c
@@ -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;
diff --git a/usr.bin/indent/parse.c b/usr.bin/indent/parse.c
index 3711a32..65d9a6b 100644
--- a/usr.bin/indent/parse.c
+++ b/usr.bin/indent/parse.c
@@ -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 (...) */
diff --git a/usr.bin/indent/pr_comment.c b/usr.bin/indent/pr_comment.c
index 32365dd..9524bf4 100644
--- a/usr.bin/indent/pr_comment.c
+++ b/usr.bin/indent/pr_comment.c
@@ -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"
OpenPOWER on IntegriCloud