#define DYN_BADVALUE -1003
/* Function declarations */
-#ifdef __STDC__
+#if defined(__STDC__) || defined(__LCLINT__)
#define P(args) args
#else
#define P(args) ()
#endif /* __STDC__ */
-DynObject DynCreate P((int el_size, int inc)), DynCopy P((DynObject obj));
-int DynDestroy P((DynObject obj)), DynRelease P((DynObject obj));
+/*@null@*//*@only@*/ DynObject DynCreate P((int el_size, int inc));
+/*@null@*//*@only@*/ DynObject DynCopy P((DynObject obj));
+int DynDestroy P((/*@only@*/DynObject obj)), DynRelease P((DynObject obj));
int DynAdd P((DynObject obj, void *el));
int DynPut P((DynObject obj, void *el, int idx));
-int DynInsert P((DynObject obj, int idx, void *els, int num));
+int DynInsert P((DynObject obj, int idx, /*@observer@*/void *els, int num));
int DynDelete P((DynObject obj, int idx));
-DynPtr DynGet P((DynObject obj, int num));
-DynPtr DynArray P((DynObject obj));
+/*@dependent@*//*@null@*/ DynPtr DynGet P((DynObject obj, int num));
+/*@observer@*/ DynPtr DynArray P((DynObject obj));
int DynDebug P((DynObject obj, int state));
int DynParanoid P((DynObject obj, int state));
int DynInitzero P((DynObject obj, int state));
int
main(argc, argv)
- int argc;
- char **argv;
+/*@unused@*/int argc;
+/*@unused@*/char **argv;
{
+ /*@-exitarg@*/
DynObject obj;
int i, s;
char d, *data;
o_size = malloc_inuse(&hist1);
#endif
+ /*@+matchanyintegral@*/
obj = DynCreate(sizeof(char), -8);
if (! obj) {
fprintf(stderr, "test: create failed.\n");
exit(1);
}
- DynDebug(obj, 1);
- DynParanoid(obj, 1);
+ if(DynDebug(obj, 1) != DYN_OK) {
+ fprintf(stderr, "test: setting paranoid failed.\n");
+ exit(1);
+ }
+ if(DynParanoid(obj, 1) != DYN_OK) {
+ fprintf(stderr, "test: setting paranoid failed.\n");
+ exit(1);
+ }
+
- if (DynGet(obj, -5) || DynGet(obj, 0) || DynGet(obj, 1000)) {
+ if ((DynGet(obj, -5) != NULL) ||
+ (DynGet(obj, 0) != NULL) || (DynGet(obj, 1000) != NULL)) {
fprintf(stderr, "test: Get did not fail when it should have.\n");
exit(1);
}
exit(1);
}
- d = 200;
+ d = '\200';
if (DynAdd(obj, &d) != DYN_OK) {
fprintf(stderr, "test: Adding %d failed.\n", i);
exit(1);
}
data = (char *) DynGet(obj, 0);
+ if(data == NULL) {
+ fprintf(stderr, "test: getting object 0 failed.\n");
+ exit(1);
+ }
s = DynSize(obj);
for (i=0; i < s; i++)
- printf("Element %d is %d.\n", i, (unsigned char) data[i]);
+ printf("Element %d is %d.\n", i, (int) data[i]);
data = (char *) DynGet(obj, 13);
- printf("Element 13 is %d.\n", (unsigned char) *data);
+ if(data == NULL) {
+ fprintf(stderr, "test: getting element 13 failed.\n");
+ exit(1);
+ }
+ printf("Element 13 is %d.\n", (int) *data);
data = (char *) DynGet(obj, DynSize(obj));
if (data) {
exit(1);
}
- printf("This should be the random string: \"%s\"\n", DynGet(obj, 14));
+ data = DynGet(obj, 14);
+ if(data == NULL) {
+ fprintf(stderr, "test: getting element 13 failed.\n");
+ exit(1);
+ }
+ printf("This should be the random string: \"%s\"\n", data);
if (DynInsert(obj, -1, "foo", 4) != DYN_BADINDEX ||
DynInsert(obj, DynSize(obj) + 1, "foo", 4) != DYN_BADINDEX ||
exit(1);
}
- printf("A new random string: \"%s\"\n", DynGet(obj, 14 +
- strlen(insert1) + 1));
- printf("This was put at the beginning: \"%s\"\n", DynGet(obj, 0));
+ data = DynGet(obj, 14 + strlen(insert1) + 1);
+ if (data == NULL) {
+ fprintf(stderr, "DynGet of 14+strelen(insert1) failed.\n");
+ exit(1);
+
+ }
+ printf("A new random string: \"%s\"\n", data);
+
+ data = DynGet(obj, 0);
+ if (data == NULL) {
+ fprintf(stderr, "DynGet of 0 failed.\n");
+ exit(1);
+
+ }
+ printf("This was put at the beginning: \"%s\"\n", data);
- DynDestroy(obj);
+ if(DynDestroy(obj) != DYN_OK) {
+ fprintf(stderr, "test: destroy failed.\n");
+ exit(1);
+ }
#ifdef _DEBUG_MALLOC_INC
c_size = malloc_inuse(&hist2);
}
#endif
+ printf("All tests pass\n");
return 0;
}