示例#1
0
void ffam_ReallocFam (ffam_Fam * fam, int Ng)
{
    fam->Resol = util_Realloc (fam->Resol, (size_t) Ng * sizeof (int));
    fam->LSize = util_Realloc (fam->LSize, (size_t) Ng * sizeof (int));
    fam->Gen = util_Realloc (fam->Gen, (size_t) Ng * sizeof (unif01_Gen *));
    fam->Ng = Ng;
}
示例#2
0
文件: sres.cpp 项目: alhunor/projects
void sres_InitBasic (sres_Basic *res, long N, char *nam)
{
   statcoll_Init (res->sVal1, N);
   statcoll_Init (res->pVal1, N);
   gofw_InitTestArray (res->sVal2, -1.0);
   gofw_InitTestArray (res->pVal2, -1.0);
   res->name = (char*) util_Realloc (res->name, 1 + strlen (nam) * sizeof (char));
   strcpy (res->name, nam);
}
示例#3
0
文件: sres.cpp 项目: alhunor/projects
void sres_InitDisc (sres_Disc *res, long N, char *nam)
{
   statcoll_Init (res->sVal1, N);
   res->sVal2 = -1.0;
   res->pLeft = -1.0;
   res->pRight = -1.0;
   res->pVal2 = -1.0;
   res->name = (char*)util_Realloc (res->name, 1 + strlen (nam) * sizeof (char));
   strcpy (res->name, nam);
   
}
示例#4
0
文件: sres.cpp 项目: alhunor/projects
void sres_InitPoisson (sres_Poisson *res, long N, double Lambda, char *nam)
{
   statcoll_Init (res->sVal1, N);
   res->Lambda = Lambda;
   res->Mu = N * Lambda;
   res->sVal2 = -1.0;
   res->pLeft = -1.0;
   res->pRight = -1.0;
   res->pVal2 = -1.0;
   res->name = (char*)util_Realloc (res->name, 1 + strlen (nam) * sizeof (char));
   strcpy (res->name, nam);
   
}
示例#5
0
文件: files.c 项目: dyjakan/honggfuzz
bool files_parseBlacklist(honggfuzz_t * hfuzz)
{
    FILE *fBl = fopen(hfuzz->blacklistFile, "rb");
    if (fBl == NULL) {
        PLOG_W("Couldn't open '%s' - R/O mode", hfuzz->blacklistFile);
        return false;
    }
    defer {
        fclose(fBl);
    };

    char *lineptr = NULL;
    /* lineptr can be NULL, but it's fine for free() */
    defer {
        free(lineptr);
    };
    size_t n = 0;
    for (;;) {
        if (getline(&lineptr, &n, fBl) == -1) {
            break;
        }

        if ((hfuzz->blacklist =
             util_Realloc(hfuzz->blacklist,
                          (hfuzz->blacklistCnt + 1) * sizeof(hfuzz->blacklist[0]))) == NULL) {
            PLOG_W("realloc failed (sz=%zu)",
                   (hfuzz->blacklistCnt + 1) * sizeof(hfuzz->blacklist[0]));
            return false;
        }

        hfuzz->blacklist[hfuzz->blacklistCnt] = strtoull(lineptr, 0, 16);
        LOG_D("Blacklist: loaded %'" PRIu64 "'", hfuzz->blacklist[hfuzz->blacklistCnt]);

        // Verify entries are sorted so we can use interpolation search
        if (hfuzz->blacklistCnt > 1) {
            if (hfuzz->blacklist[hfuzz->blacklistCnt - 1] > hfuzz->blacklist[hfuzz->blacklistCnt]) {
                LOG_F
                    ("Blacklist file not sorted. Use 'tools/createStackBlacklist.sh' to sort records");
                return false;
            }
        }
        hfuzz->blacklistCnt += 1;
    }

    if (hfuzz->blacklistCnt > 0) {
        LOG_I("Loaded %zu stack hash(es) from the blacklist file", hfuzz->blacklistCnt);
    } else {
        LOG_F("Empty stack hashes blacklist file '%s'", hfuzz->blacklistFile);
    }
    return true;
}
示例#6
0
static void InitRes (
   sspectral_Res *res,
   long N,
   long jmin,
   long jmax,
   char *nam
)
/* 
 * Initializes the sspectral_Res structure
 */
{
   long j;
   sres_InitBasic (res->Bas, N, nam);
   if (jmax > res->jmax)
      res->Coef = util_Realloc (res->Coef, (jmax + 200) * sizeof (double));
   for (j = 0; j <= jmax; j++)
      res->Coef[j] = 0.0;
   res->jmin = jmin;
   res->jmax = jmax;
   res->Bas->name = util_Realloc (res->Bas->name,
                                  1 + strlen (nam) * sizeof (char));
   strcpy (res->Bas->name, nam);
}
示例#7
0
void sres_InitChi2 (sres_Chi2 *res, long N, long jmax, char *nam)
{
    statcoll_Init (res->sVal1, N);
    statcoll_Init (res->pVal1, N);

    if (jmax < 0) {
        if (res->jmax > 0) {
            res->NbExp = util_Free (res->NbExp);
            res->Count = util_Free (res->Count);
            res->Loc = util_Free (res->Loc);
        }
    } else {
        if (res->jmax < 0) {
            res->NbExp = util_Calloc ((size_t) (jmax + 1), sizeof (double));
            res->Count = util_Calloc ((size_t) (jmax + 1), sizeof (long));
            res->Loc = util_Calloc ((size_t) (jmax + 1), sizeof (long));
        } else {
            int j;
            res->NbExp =
                util_Realloc (res->NbExp, (jmax + 1) * sizeof (double));
            res->Count = util_Realloc (res->Count, (jmax + 1) * sizeof (long));
            res->Loc = util_Realloc (res->Loc, (jmax + 1) * sizeof (long));
            for (j = 0; j <= jmax; j++) {
                res->NbExp[j] = 0.0;
                res->Count[j] = 0;
                res->Loc[j] = 0;
            }
        }
    }
    res->degFree = 0;
    res->jmin = 0;
    res->jmax = jmax;
    gofw_InitTestArray (res->sVal2, -1.0);
    gofw_InitTestArray (res->pVal2, -1.0);
    res->name = util_Realloc (res->name, 1 + strlen (nam) * sizeof (char));
    strcpy (res->name, nam);
}
示例#8
0
static void InitRes (
   sentrop_Res *res,          /* Results holder */
   long N,                    /* Number of replications */
   int jmax,                  /* Maximal index for Count */
   char *nam
)
/* 
 * Initializes res
 */
{
   sres_InitBasic (res->Bas, N, nam);
   if (jmax > res->jmax)
      res->Count = util_Realloc (res->Count, (jmax + 1) * sizeof (long));
   res->jmax = jmax;
}
示例#9
0
unif01_Gen * utaus_CreateCombTaus3T (unsigned int k1, unsigned int k2,
   unsigned int k3, unsigned int q1, unsigned int q2, unsigned int q3,
   unsigned int s1, unsigned int s2, unsigned int s3, unsigned int Y1,
   unsigned int Y2, unsigned int Y3)
{
   unif01_Gen *gen;
   size_t j;

   gen = utaus_CreateCombTaus3 (
          k1, k2, k3, q1, q2, q3, s1, s2, s3, Y1, Y2, Y3);
   j = strlen (gen->name);
   gen->name = util_Realloc (gen->name, (j + 2) * sizeof (char));
   j = strcspn (gen->name, ":");
   mystr_Insert (gen->name, "T", (unsigned int) j);
   gen->GetU01  = &CombTaus3T_U01;
   gen->GetBits = &CombTaus3T_Bits;
 
   return gen;
}
示例#10
0
unif01_Gen *utaus_CreateTausJ (unsigned int k, unsigned int q,
   unsigned int s, unsigned int j, unsigned int Y)
{
   unif01_Gen *gen;
   Taus_param *param;
   unsigned int pos;
   int found;
   size_t len;
   char str[LEN1 + 1] = "";

   gen = CreateTaus_0 ("utaus_CreateTausJ", k, q, s, Y);
   param = gen->param;
   param->J = j;
   gen->GetBits = &TausJ_Bits;
   gen->GetU01  = &TausJ_U01;

   addstr_Uint (str, ",  j = ", j);
   len = strlen (gen->name) + strlen (str);
   gen->name = util_Realloc (gen->name, (len + 1) * sizeof (char));
   mystr_Position (",  Y =", gen->name, 0, &pos, &found);
   mystr_Insert (gen->name, str, pos);
   return gen;
}
示例#11
0
文件: files.c 项目: dyjakan/honggfuzz
static bool files_readdir(honggfuzz_t * hfuzz)
{
    DIR *dir = opendir(hfuzz->inputDir);
    if (!dir) {
        PLOG_W("Couldn't open dir '%s'", hfuzz->inputDir);
        return false;
    }
    defer {
        closedir(dir);
    };

    size_t maxSize = 0UL;
    unsigned count = 0;
    for (;;) {
        errno = 0;
        struct dirent *res = readdir(dir);
        if (res == NULL && errno != 0) {
            PLOG_W("Couldn't read the '%s' dir", hfuzz->inputDir);
            return false;
        }

        if (res == NULL) {
            break;
        }

        char path[PATH_MAX];
        snprintf(path, sizeof(path), "%s/%s", hfuzz->inputDir, res->d_name);
        struct stat st;
        if (stat(path, &st) == -1) {
            LOG_W("Couldn't stat() the '%s' file", path);
            continue;
        }

        if (!S_ISREG(st.st_mode)) {
            LOG_D("'%s' is not a regular file, skipping", path);
            continue;
        }

        if (st.st_size == 0ULL) {
            LOG_D("'%s' is empty", path);
            continue;
        }

        if (hfuzz->maxFileSz != 0UL && st.st_size > (off_t) hfuzz->maxFileSz) {
            LOG_W("File '%s' is bigger than maximal defined file size (-F): %" PRId64 " > %"
                  PRId64, path, (int64_t) st.st_size, (int64_t) hfuzz->maxFileSz);
            continue;
        }

        if (!(hfuzz->files = util_Realloc(hfuzz->files, sizeof(char *) * (count + 1)))) {
            PLOG_W("Couldn't allocate memory");
            return false;
        }

        if ((size_t) st.st_size > maxSize) {
            maxSize = st.st_size;
        }
        hfuzz->files[count] = util_StrDup(path);
        hfuzz->fileCnt = ++count;
        LOG_D("Added '%s' to the list of input files", path);
    }

    if (count == 0) {
        LOG_W("Directory '%s' doesn't contain any regular files", hfuzz->inputDir);
        return false;
    }

    if (hfuzz->maxFileSz == 0UL) {
        hfuzz->maxFileSz = maxSize;
    }
    LOG_I("%zu input files have been added to the list. Max file size: %zu", hfuzz->fileCnt,
          hfuzz->maxFileSz);
    return true;
}