int main() { int length1 = __VERIFIER_nondet_int(); int length2 = __VERIFIER_nondet_int(); if (length1 < 1) { length1 = 1; } if (length2 < 1) { length2 = 1; } char* nondetString1 = (char*) alloca(length1 * sizeof(char)); char* nondetString2 = (char*) alloca(length2 * sizeof(char)); nondetString1[length1-1] = '\0'; nondetString2[length2-1] = '\0'; return cstrstr(nondetString1,nondetString2); }
/* rm -rf : first empty directory, then remove directory */ int rm_rf_trashdir(char *dirname) { char buf[MAX_PATHLEN], *bufp; DIR *dirp; struct dirent *direntp; if (dirname == NULL || !*dirname) return -1; /* safety check */ bufprintf(buf, sizeof(buf), "%s/", PARAM_TRASHDIR); path_strip(buf); if (strncmp(buf, dirname, strlen(buf)) || cstrstr(dirname, "..") != NULL) return -1; cstrcpy(buf, dirname, MAX_PATHLEN); bufp = buf+strlen(buf)-1; if (*bufp != '/') { bufp++; *bufp = '/'; bufp++; *bufp = 0; } if ((dirp = opendir(buf)) == NULL) return -1; while((direntp = readdir(dirp)) != NULL) { /* check for '.' and '..' directory */ if (direntp->d_name[0] == '.' && (!direntp->d_name[1] || (direntp->d_name[1] == '.' && !direntp->d_name[2]))) continue; cstrcpy(bufp, direntp->d_name, MAX_PATHLEN); unlink(buf); /* note: trash/ is not cached ; it's ok not to use unlink_file() */ } closedir(dirp); return remove_dir(dirname); }
/* generate C to put netCDF record from in-memory data */ static void gen_load_c( void *rec_start ) { int idim, ival; char *val_string; char *charvalp = NULL; short *shortvalp = NULL; int *intvalp = NULL; float *floatvalp = NULL; double *doublevalp = NULL; unsigned char *ubytevalp = NULL; unsigned short *ushortvalp = NULL; unsigned int *uintvalp = NULL; long long *int64valp = NULL; unsigned long long *uint64valp = NULL; char stmnt[C_MAX_STMNT]; size_t stmnt_len; char s2[C_MAX_STMNT]; if (!vars[varnum].has_data) return; s2[0] = '\0'; cline(""); sprintf(stmnt, " {\t\t\t/* store %s */", vars[varnum].name); cline(stmnt); if (vars[varnum].ndims > 0) { if (vars[varnum].dims[0] == rec_dim) { sprintf(stmnt, " static MPI_Offset %s_start[RANK_%s];", vars[varnum].lname, vars[varnum].lname); cline(stmnt); sprintf(stmnt, " static MPI_Offset %s_count[RANK_%s];", vars[varnum].lname, vars[varnum].lname); cline(stmnt); } /* load variable with data values using static initialization */ sprintf(stmnt, " static %s %s[] = {", ncctype(vars[varnum].type), vars[varnum].lname); stmnt_len = strlen(stmnt); switch (vars[varnum].type) { case NC_CHAR: val_string = cstrstr((char *) rec_start, var_len); sprintf(s2, "%s", val_string); strncat(stmnt, s2, C_MAX_STMNT - strlen(stmnt) ); free(val_string); break; default: switch (vars[varnum].type) { case NC_BYTE: charvalp = (char *) rec_start; break; case NC_SHORT: shortvalp = (short *) rec_start; break; case NC_INT: intvalp = (int *) rec_start; break; case NC_FLOAT: floatvalp = (float *) rec_start; break; case NC_DOUBLE: doublevalp = (double *) rec_start; break; case NC_UBYTE: ubytevalp = (unsigned char *) rec_start; break; case NC_USHORT: ushortvalp = (unsigned short *) rec_start; break; case NC_UINT: uintvalp = (unsigned int *) rec_start; break; case NC_INT64: int64valp = (long long *) rec_start; break; case NC_UINT64: uint64valp = (unsigned long long *) rec_start; break; default: derror("Unhandled type %d\n", vars[varnum].type); return; } for (ival = 0; ival < var_len-1; ival++) { switch (vars[varnum].type) { case NC_BYTE: sprintf(s2, "%d, ", *charvalp++); break; case NC_SHORT: sprintf(s2, "%d, ", *shortvalp++); break; case NC_INT: sprintf(s2, "%ld, ", (long)*intvalp++); break; case NC_FLOAT: sprintf(s2, "%.8g, ", *floatvalp++); break; case NC_DOUBLE: sprintf(s2, "%#.16g", *doublevalp++); tztrim(s2); strcat(s2, ", "); break; case NC_UBYTE: sprintf(s2, "%hhu, ", (unsigned char)*ubytevalp++); break; case NC_USHORT: sprintf(s2, "%hu, ", (unsigned short)*ushortvalp++); break; case NC_UINT: sprintf(s2, "%u, ", (unsigned int)*uintvalp++); break; case NC_INT64: sprintf(s2, "%lld, ", (long long)*int64valp++); break; case NC_UINT64: sprintf(s2, "%llu, ", (unsigned long long)*uint64valp++); break; default: derror("Unhandled type %d\n", vars[varnum].type); return; } stmnt_len += strlen(s2); if (stmnt_len < C_MAX_STMNT) strcat(stmnt, s2); else { cline(stmnt); strcpy(stmnt,s2); stmnt_len = strlen(stmnt); } } for (;ival < var_len; ival++) { switch (vars[varnum].type) { case NC_BYTE: sprintf(s2, "%d", *charvalp); break; case NC_SHORT: sprintf(s2, "%d", *shortvalp); break; case NC_INT: sprintf(s2, "%ld", (long)*intvalp); break; case NC_FLOAT: sprintf(s2, "%.8g", *floatvalp); break; case NC_DOUBLE: sprintf(s2, "%#.16g", *doublevalp++); tztrim(s2); break; case NC_UBYTE: sprintf(s2, "%hhu, ", (unsigned char)*ubytevalp++); break; case NC_USHORT: sprintf(s2, "%hu, ", (unsigned short)*ushortvalp++); break; case NC_UINT: sprintf(s2, "%u, ", (unsigned int)*uintvalp++); break; case NC_INT64: sprintf(s2, "%lld, ", (long long)*int64valp++); break; case NC_UINT64: sprintf(s2, "%llu, ", (unsigned long long)*uint64valp++); break; default: derror("Unhandled type %d\n", vars[varnum].type); break; } stmnt_len += strlen(s2); if (stmnt_len < C_MAX_STMNT) strcat(stmnt, s2); else { cline(stmnt); strcpy(stmnt,s2); stmnt_len = strlen(stmnt); } } break; } strcat(stmnt,"};"); cline(stmnt); if (vars[varnum].dims[0] == rec_dim) { sprintf(stmnt, " %s_len = %lu; /* number of records of %s data */", dims[rec_dim].lname, (unsigned long)vars[varnum].nrecs, /* number of recs for this variable */ vars[varnum].name); cline(stmnt); for (idim = 0; idim < vars[varnum].ndims; idim++) { sprintf(stmnt, " %s_start[%d] = 0;", vars[varnum].lname, idim); cline(stmnt); } for (idim = 0; idim < vars[varnum].ndims; idim++) { sprintf(stmnt, " %s_count[%d] = %s_len;", vars[varnum].lname, idim, dims[vars[varnum].dims[idim]].lname); cline(stmnt); } } if (vars[varnum].dims[0] == rec_dim) { sprintf(stmnt, " stat = ncmpi_put_vara_%s_all(ncid, %s_id, %s_start, %s_count, %s);", ncstype(vars[varnum].type), vars[varnum].lname, vars[varnum].lname, vars[varnum].lname, vars[varnum].lname); cline(stmnt); } else { /* non-record variables */ cline(" ncmpi_begin_indep_data(ncid);"); sprintf(stmnt, " stat = ncmpi_put_var_%s(ncid, %s_id, %s);", ncstype(vars[varnum].type), vars[varnum].lname, vars[varnum].lname); cline(stmnt); cline(" ncmpi_end_indep_data(ncid);"); } } else { /* scalar variables */ /* load variable with data values using static initialization */ sprintf(stmnt, " static %s %s = ", ncctype(vars[varnum].type), vars[varnum].lname); switch (vars[varnum].type) { case NC_CHAR: val_string = cstrstr((char *) rec_start, var_len); val_string[strlen(val_string)-1] = '\0'; sprintf(s2, "'%s'", &val_string[1]); free(val_string); break; case NC_BYTE: charvalp = (char *) rec_start; sprintf(s2, "%d", *charvalp); break; case NC_SHORT: shortvalp = (short *) rec_start; sprintf(s2, "%d", *shortvalp); break; case NC_INT: intvalp = (int *) rec_start; sprintf(s2, "%ld", (long)*intvalp); break; case NC_FLOAT: floatvalp = (float *) rec_start; sprintf(s2, "%.8g", *floatvalp); break; case NC_DOUBLE: doublevalp = (double *) rec_start; sprintf(s2, "%#.16g", *doublevalp++); tztrim(s2); break; case NC_UBYTE: ubytevalp = (unsigned char *) rec_start; sprintf(s2, "%hhu", (unsigned char)*ubytevalp); break; case NC_USHORT: ushortvalp = (unsigned short *) rec_start; sprintf(s2, "%hu", (unsigned short)*ushortvalp); break; case NC_UINT: uintvalp = (unsigned int *) rec_start; sprintf(s2, "%u", (unsigned int)*uintvalp); break; case NC_INT64: int64valp = (long long *) rec_start; sprintf(s2, "%lld", (long long)*int64valp); break; case NC_UINT64: uint64valp = (unsigned long long *) rec_start; sprintf(s2, "%llu", (unsigned long long)*uint64valp); break; default: derror("Unhandled type %d\n", vars[varnum].type); break; } strncat(stmnt, s2, C_MAX_STMNT - strlen(stmnt) ); strcat(stmnt,";"); cline(stmnt); cline(" ncmpi_begin_indep_data(ncid);"); sprintf(stmnt, " stat = ncmpi_put_var_%s(ncid, %s_id, &%s);", ncstype(vars[varnum].type), vars[varnum].lname, vars[varnum].lname); cline(stmnt); cline(" ncmpi_end_indep_data(ncid);"); } cline(" check_err(stat,__LINE__,__FILE__);"); cline(" }"); }
/* find_Room() with abbreviated name */ Room *find_abbrevRoom(User *usr, char *name) { Room *r; char room_name[MAX_LINE+2], match[MAX_LINE+2]; if (name == NULL || !*name || usr == NULL) return NULL; if ((r = find_Room(usr, name)) == NULL) { int l; l = strlen(name); for(r = AllRooms; r != NULL; r = r->next) { if (!strncmp(r->name, name, l)) { if (r->number == LOBBY_ROOM || r->number == MAIL_ROOM || r->number == HOME_ROOM) return find_Roombynumber(usr, r->number); if (!room_visible(usr, r)) continue; if (!PARAM_HAVE_CHATROOMS && (r->flags & ROOM_CHATROOM)) continue; return r; } } /* didn't find any room, try a substring that matches whole words */ bufprintf(match, sizeof(match), " %s ", name); for(r = AllRooms; r != NULL; r = r->next) { bufprintf(room_name, sizeof(room_name), " %s ", r->name); if (cstrstr(room_name, match) != NULL) { if (r->number == LOBBY_ROOM || r->number == MAIL_ROOM || r->number == HOME_ROOM) return find_Roombynumber(usr, r->number); if (!room_visible(usr, r)) continue; if (!PARAM_HAVE_CHATROOMS && (r->flags & ROOM_CHATROOM)) continue; return r; } } /* didn't find any room, try a substring that matches half words */ for(r = AllRooms; r != NULL; r = r->next) { if (cstrstr(r->name, name) != NULL) { if (r->number == LOBBY_ROOM || r->number == MAIL_ROOM || r->number == HOME_ROOM) return find_Roombynumber(usr, r->number); if (!room_visible(usr, r)) continue; if (!PARAM_HAVE_CHATROOMS && (r->flags & ROOM_CHATROOM)) continue; return r; } } return NULL; } return r; }
/* * Generate C code for creating netCDF from in-memory structure. */ static void gen_c( const char *filename) { int idim, ivar, iatt, jatt, maxdims; int vector_atts; char *val_string; char stmnt[C_MAX_STMNT]; /* wrap in main program */ cline("#include <stdio.h>"); cline("#include <stdlib.h>"); cline("#include <netcdf.h>"); cline(""); cline("void"); cline("check_err(const int stat, const int line, const char *file) {"); cline(" if (stat != NC_NOERR) {"); cline(" (void) fprintf(stderr, \"line %d of %s: %s\\n\", line, file, nc_strerror(stat));"); cline(" exit(1);"); cline(" }"); cline("}"); cline(""); cline("int"); sprintf(stmnt, "main() {\t\t\t/* create %s */", filename); cline(stmnt); /* create necessary declarations */ cline(""); cline(" int stat;\t\t\t/* return status */"); cline(" int ncid;\t\t\t/* netCDF id */"); if (ndims > 0) { cline(""); cline(" /* dimension ids */"); for (idim = 0; idim < ndims; idim++) { sprintf(stmnt, " int %s_dim;", dims[idim].lname); cline(stmnt); } cline(""); cline(" /* dimension lengths */"); for (idim = 0; idim < ndims; idim++) { if (dims[idim].size == NC_UNLIMITED) { sprintf(stmnt, " size_t %s_len = NC_UNLIMITED;", dims[idim].lname); } else { sprintf(stmnt, " size_t %s_len = %lu;", dims[idim].lname, (unsigned long) dims[idim].size); } cline(stmnt); } } maxdims = 0; /* most dimensions of any variable */ for (ivar = 0; ivar < nvars; ivar++) if (vars[ivar].ndims > maxdims) maxdims = vars[ivar].ndims; if (nvars > 0) { cline(""); cline(" /* variable ids */"); for (ivar = 0; ivar < nvars; ivar++) { sprintf(stmnt, " int %s_id;", vars[ivar].lname); cline(stmnt); } cline(""); cline(" /* rank (number of dimensions) for each variable */"); for (ivar = 0; ivar < nvars; ivar++) { sprintf(stmnt, "# define RANK_%s %d", vars[ivar].lname, vars[ivar].ndims); cline(stmnt); } if (maxdims > 0) { /* we have dimensioned variables */ cline(""); cline(" /* variable shapes */"); for (ivar = 0; ivar < nvars; ivar++) { if (vars[ivar].ndims > 0) { sprintf(stmnt, " int %s_dims[RANK_%s];", vars[ivar].lname, vars[ivar].lname); cline(stmnt); } } } } /* determine if we need any attribute vectors */ vector_atts = 0; for (iatt = 0; iatt < natts; iatt++) { if (atts[iatt].type != NC_CHAR) { vector_atts = 1; break; } } if (vector_atts) { cline(""); cline(" /* attribute vectors */"); for (iatt = 0; iatt < natts; iatt++) { if (atts[iatt].type != NC_CHAR) { sprintf(stmnt, " %s %s_%s[%lu];", ncatype(atts[iatt].type), atts[iatt].var == -1 ? "cdf" : vars[atts[iatt].var].lname, atts[iatt].lname, (unsigned long) atts[iatt].len); cline(stmnt); } } } /* create netCDF file, uses NC_CLOBBER mode */ cline(""); cline(" /* enter define mode */"); if (!cmode_modifier) { sprintf(stmnt, " stat = nc_create(\"%s\", NC_CLOBBER, &ncid);", filename); } else if (cmode_modifier & NC_64BIT_OFFSET) { sprintf(stmnt, " stat = nc_create(\"%s\", NC_CLOBBER|NC_64BIT_OFFSET, &ncid);", filename); #ifdef USE_NETCDF4 } else if (cmode_modifier & NC_CLASSIC_MODEL) { sprintf(stmnt, " stat = nc_create(\"%s\", NC_CLOBBER|NC_NETCDF4|NC_CLASSIC_MODEL, &ncid);", filename); } else if (cmode_modifier & NC_NETCDF4) { sprintf(stmnt, " stat = nc_create(\"%s\", NC_CLOBBER|NC_NETCDF4, &ncid);", filename); #endif } else { derror("unknown cmode modifier"); } cline(stmnt); cline(" check_err(stat,__LINE__,__FILE__);"); /* define dimensions from info in dims array */ if (ndims > 0) { cline(""); cline(" /* define dimensions */"); } for (idim = 0; idim < ndims; idim++) { sprintf(stmnt, " stat = nc_def_dim(ncid, \"%s\", %s_len, &%s_dim);", dims[idim].name, dims[idim].lname, dims[idim].lname); cline(stmnt); cline(" check_err(stat,__LINE__,__FILE__);"); } /* define variables from info in vars array */ if (nvars > 0) { cline(""); cline(" /* define variables */"); for (ivar = 0; ivar < nvars; ivar++) { cline(""); for (idim = 0; idim < vars[ivar].ndims; idim++) { sprintf(stmnt, " %s_dims[%d] = %s_dim;", vars[ivar].lname, idim, dims[vars[ivar].dims[idim]].lname); cline(stmnt); } if (vars[ivar].ndims > 0) { /* a dimensioned variable */ sprintf(stmnt, " stat = nc_def_var(ncid, \"%s\", %s, RANK_%s, %s_dims, &%s_id);", vars[ivar].name, nctype(vars[ivar].type), vars[ivar].lname, vars[ivar].lname, vars[ivar].lname); } else { /* a scalar */ sprintf(stmnt, " stat = nc_def_var(ncid, \"%s\", %s, RANK_%s, 0, &%s_id);", vars[ivar].name, nctype(vars[ivar].type), vars[ivar].lname, vars[ivar].lname); } cline(stmnt); cline(" check_err(stat,__LINE__,__FILE__);"); } } /* define attributes from info in atts array */ if (natts > 0) { cline(""); cline(" /* assign attributes */"); for (iatt = 0; iatt < natts; iatt++) { if (atts[iatt].type == NC_CHAR) { /* string */ val_string = cstrstr((char *) atts[iatt].val, atts[iatt].len); sprintf(stmnt, " stat = nc_put_att_text(ncid, %s%s, \"%s\", %lu, %s);", atts[iatt].var == -1 ? "NC_GLOBAL" : vars[atts[iatt].var].lname, atts[iatt].var == -1 ? "" : "_id", atts[iatt].name, (unsigned long) atts[iatt].len, val_string); cline(stmnt); free (val_string); } else { /* vector attribute */ for (jatt = 0; jatt < atts[iatt].len ; jatt++) { val_string = cstring(atts[iatt].type,atts[iatt].val,jatt); sprintf(stmnt, " %s_%s[%d] = %s;", atts[iatt].var == -1 ? "cdf" : vars[atts[iatt].var].lname, atts[iatt].lname, jatt, val_string); cline(stmnt); free (val_string); } sprintf(stmnt, " stat = nc_put_att_%s(ncid, %s%s, \"%s\", %s, %lu, %s_%s);", ncatype(atts[iatt].type), atts[iatt].var == -1 ? "NC_GLOBAL" : vars[atts[iatt].var].lname, atts[iatt].var == -1 ? "" : "_id", atts[iatt].name, nctype(atts[iatt].type), (unsigned long) atts[iatt].len, atts[iatt].var == -1 ? "cdf" : vars[atts[iatt].var].lname, atts[iatt].lname); cline(stmnt); } cline(" check_err(stat,__LINE__,__FILE__);"); } } if (nofill_flag) { cline(" /* don't initialize variables with fill values */"); cline(" stat = nc_set_fill(ncid, NC_NOFILL, 0);"); cline(" check_err(stat,__LINE__,__FILE__);"); } cline(""); cline(" /* leave define mode */"); cline(" stat = nc_enddef (ncid);"); cline(" check_err(stat,__LINE__,__FILE__);"); }