From 76bdfa96b37825d8dfc30fc835ab1be980bb22b9 Mon Sep 17 00:00:00 2001 From: "coop%netscape.com" Date: Tue, 16 Feb 1999 18:41:30 +0000 Subject: [PATCH] NOT YET PART OF SEAMONKEY: * eliminated compiler warnings on Linux * added extra error checking for file manipulation in SimpleTypeLib and xpt_dump * removed erroneous comment from xpt_struct.h --- xpcom/libxpt/public/xpt_struct.h | 2 -- xpcom/libxpt/src/xpt_xdr.c | 6 +++--- xpcom/libxpt/tests/SimpleTypeLib.c | 13 ++++++++++--- xpcom/libxpt/tools/xpt_dump.c | 5 +++-- xpcom/typelib/xpt/public/xpt_struct.h | 2 -- xpcom/typelib/xpt/src/xpt_xdr.c | 6 +++--- xpcom/typelib/xpt/tests/SimpleTypeLib.c | 13 ++++++++++--- xpcom/typelib/xpt/tools/xpt_dump.c | 5 +++-- 8 files changed, 32 insertions(+), 20 deletions(-) diff --git a/xpcom/libxpt/public/xpt_struct.h b/xpcom/libxpt/public/xpt_struct.h index 0aba5b8ca326..896e69cf0fc6 100644 --- a/xpcom/libxpt/public/xpt_struct.h +++ b/xpcom/libxpt/public/xpt_struct.h @@ -224,8 +224,6 @@ struct XPTTypeDescriptorPrefix { #define XPT_TDP_IS_UNIQUE_POINTER(flags) (flags & XPT_TDP_UNIQUE_POINTER) #define XPT_TDP_IS_REFERENCE(flags) (flags & XPT_TDP_REFERENCE) -/* XXX TD #defines should include required flag bits! */ - /* * The following enum maps mnemonic names to the different numeric values * of XPTTypeDescriptor->tag. diff --git a/xpcom/libxpt/src/xpt_xdr.c b/xpcom/libxpt/src/xpt_xdr.c index 97f623c1eb5f..f523aa53736f 100644 --- a/xpcom/libxpt/src/xpt_xdr.c +++ b/xpcom/libxpt/src/xpt_xdr.c @@ -57,14 +57,14 @@ CheckForRepeat(XPTCursor *cursor, void **addrp, XPTPool pool, int len, ((cursor)->state->data_offset && \ ((cursor)->offset - 1 + (space) > (cursor)->state->data_offset)) \ ? (DBG(("no space left in HEADER %d + %d > %d\n", (cursor)->offset, \ - (space), (cursor)->state->data_offset)), PR_FALSE) \ + (space), (cursor)->state->data_offset)) && PR_FALSE) \ : PR_TRUE) : \ /* if we're in the data area and we're about to exceed the allocation */ \ (CURS_POOL_OFFSET(cursor) + (space) > (cursor)->state->pool->allocated ? \ /* then grow if we're in ENCODE mode */ \ - (ENCODING(cursor) ? GrowPool((cursor)->state->pool) \ + (ENCODING(cursor) ? GrowPool((cursor)->state->pool) \ /* and fail if we're in DECODE mode */ \ - : (DBG(("can't extend in DECODE")), PR_FALSE)) \ + : (DBG(("can't extend in DECODE")) && PR_FALSE)) \ /* otherwise we're OK */ \ : PR_TRUE)) diff --git a/xpcom/libxpt/tests/SimpleTypeLib.c b/xpcom/libxpt/tests/SimpleTypeLib.c index de0370f06990..d11a7a0e9699 100644 --- a/xpcom/libxpt/tests/SimpleTypeLib.c +++ b/xpcom/libxpt/tests/SimpleTypeLib.c @@ -45,7 +45,7 @@ struct nsID iid = { {0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff} }; -XPTTypeDescriptor td_void = { TD_VOID }; +XPTTypeDescriptor td_void = {}; int main(int argc, char **argv) @@ -62,6 +62,8 @@ main(int argc, char **argv) uint32 len, header_sz; PRBool ok; + + td_void.prefix.flags = TD_VOID; if (argc != 2) { fprintf(stderr, "Usage: %s \n" @@ -140,9 +142,14 @@ main(int argc, char **argv) XPT_GetXDRData(state, XPT_DATA, &data, &len); fwrite(data, len, 1, out); - fclose(out); - XPT_DestroyXDRState(state); + if (ferror(out) != 0 || fclose(out) != 0) { + fprintf(stderr, "\nError writing file: %s\n\n", argv[1]); + } else { + fprintf(stderr, "\nFile written: %s\n\n", argv[1]); + } + XPT_DestroyXDRState(state); + /* XXX DestroyHeader */ return 0; } diff --git a/xpcom/libxpt/tools/xpt_dump.c b/xpcom/libxpt/tools/xpt_dump.c index aaaf979158ea..4b0e43e3a0f5 100644 --- a/xpcom/libxpt/tools/xpt_dump.c +++ b/xpcom/libxpt/tools/xpt_dump.c @@ -139,6 +139,9 @@ main(int argc, char **argv) if (flen > 0) { fread(whole, flen, 1, in); + if (ferror(in) != 0 || fclose(in) != 0) + perror("FAILED: Unable to read typelib file.\n"); + state = XPT_NewXDRState(XPT_DECODE, whole, flen); if (!XPT_MakeCursor(state, XPT_HEADER, 0, cursor)) { fprintf(stdout, "MakeCursor failed\n"); @@ -158,8 +161,6 @@ main(int argc, char **argv) free(whole); } - fclose(in); - return 0; } diff --git a/xpcom/typelib/xpt/public/xpt_struct.h b/xpcom/typelib/xpt/public/xpt_struct.h index 0aba5b8ca326..896e69cf0fc6 100644 --- a/xpcom/typelib/xpt/public/xpt_struct.h +++ b/xpcom/typelib/xpt/public/xpt_struct.h @@ -224,8 +224,6 @@ struct XPTTypeDescriptorPrefix { #define XPT_TDP_IS_UNIQUE_POINTER(flags) (flags & XPT_TDP_UNIQUE_POINTER) #define XPT_TDP_IS_REFERENCE(flags) (flags & XPT_TDP_REFERENCE) -/* XXX TD #defines should include required flag bits! */ - /* * The following enum maps mnemonic names to the different numeric values * of XPTTypeDescriptor->tag. diff --git a/xpcom/typelib/xpt/src/xpt_xdr.c b/xpcom/typelib/xpt/src/xpt_xdr.c index 97f623c1eb5f..f523aa53736f 100644 --- a/xpcom/typelib/xpt/src/xpt_xdr.c +++ b/xpcom/typelib/xpt/src/xpt_xdr.c @@ -57,14 +57,14 @@ CheckForRepeat(XPTCursor *cursor, void **addrp, XPTPool pool, int len, ((cursor)->state->data_offset && \ ((cursor)->offset - 1 + (space) > (cursor)->state->data_offset)) \ ? (DBG(("no space left in HEADER %d + %d > %d\n", (cursor)->offset, \ - (space), (cursor)->state->data_offset)), PR_FALSE) \ + (space), (cursor)->state->data_offset)) && PR_FALSE) \ : PR_TRUE) : \ /* if we're in the data area and we're about to exceed the allocation */ \ (CURS_POOL_OFFSET(cursor) + (space) > (cursor)->state->pool->allocated ? \ /* then grow if we're in ENCODE mode */ \ - (ENCODING(cursor) ? GrowPool((cursor)->state->pool) \ + (ENCODING(cursor) ? GrowPool((cursor)->state->pool) \ /* and fail if we're in DECODE mode */ \ - : (DBG(("can't extend in DECODE")), PR_FALSE)) \ + : (DBG(("can't extend in DECODE")) && PR_FALSE)) \ /* otherwise we're OK */ \ : PR_TRUE)) diff --git a/xpcom/typelib/xpt/tests/SimpleTypeLib.c b/xpcom/typelib/xpt/tests/SimpleTypeLib.c index de0370f06990..d11a7a0e9699 100644 --- a/xpcom/typelib/xpt/tests/SimpleTypeLib.c +++ b/xpcom/typelib/xpt/tests/SimpleTypeLib.c @@ -45,7 +45,7 @@ struct nsID iid = { {0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff} }; -XPTTypeDescriptor td_void = { TD_VOID }; +XPTTypeDescriptor td_void = {}; int main(int argc, char **argv) @@ -62,6 +62,8 @@ main(int argc, char **argv) uint32 len, header_sz; PRBool ok; + + td_void.prefix.flags = TD_VOID; if (argc != 2) { fprintf(stderr, "Usage: %s \n" @@ -140,9 +142,14 @@ main(int argc, char **argv) XPT_GetXDRData(state, XPT_DATA, &data, &len); fwrite(data, len, 1, out); - fclose(out); - XPT_DestroyXDRState(state); + if (ferror(out) != 0 || fclose(out) != 0) { + fprintf(stderr, "\nError writing file: %s\n\n", argv[1]); + } else { + fprintf(stderr, "\nFile written: %s\n\n", argv[1]); + } + XPT_DestroyXDRState(state); + /* XXX DestroyHeader */ return 0; } diff --git a/xpcom/typelib/xpt/tools/xpt_dump.c b/xpcom/typelib/xpt/tools/xpt_dump.c index aaaf979158ea..4b0e43e3a0f5 100644 --- a/xpcom/typelib/xpt/tools/xpt_dump.c +++ b/xpcom/typelib/xpt/tools/xpt_dump.c @@ -139,6 +139,9 @@ main(int argc, char **argv) if (flen > 0) { fread(whole, flen, 1, in); + if (ferror(in) != 0 || fclose(in) != 0) + perror("FAILED: Unable to read typelib file.\n"); + state = XPT_NewXDRState(XPT_DECODE, whole, flen); if (!XPT_MakeCursor(state, XPT_HEADER, 0, cursor)) { fprintf(stdout, "MakeCursor failed\n"); @@ -158,8 +161,6 @@ main(int argc, char **argv) free(whole); } - fclose(in); - return 0; }