Ejemplo n.º 1
0
CDFstatus ValidateAttributeLinks (struct CDFstruct *CDF, vFILE *fp,
                                  Logical debug)
{
    CDFstatus status;
    OFF_T offset, nextADR, AgrEDRhead, AzEDRhead;
    Int32 num, numgrEntries, maxgrEntry, numzEntries, maxzEntry, scope;
    int ix, *visit;

    visit = (int *) cdf_AllocateMemory (GDR.NumAttr * sizeof(Int32), NULL);
    if (visit == NULL) return BAD_MALLOC;
    for (ix = 0; ix < GDR.NumAttr; ++ix)
        visit[ix] = 0;
    offset = GDR.ADRhead;
    for (ix = 0; ix < GDR.NumAttr; ++ix) {
        status = ValidateADR (CDF, fp, offset, debug);
        if (status != CDF_OK) {
            cdf_FreeMemory (visit, NULL);
            return status;
        }
        status = ReadADR64 (fp, offset,
                            ADR_NUM, &num,
                            ADR_ADRNEXT, &nextADR,
                            ADR_AgrEDRHEAD, &AgrEDRhead,
                            ADR_NgrENTRIES, &numgrEntries,
                            ADR_MAXgrENTRY, &maxgrEntry,
                            ADR_AzEDRHEAD, &AzEDRhead,
                            ADR_NzENTRIES, &numzEntries,
                            ADR_MAXzENTRY, &maxzEntry,
                            ADR_NULL);
        if (numgrEntries > 0) {
            status = ValidateAttributeEntryLink (CDF, fp, num, FALSE, AgrEDRhead,
                                                 numgrEntries, maxgrEntry, debug);
            if (status != CDF_OK) {
                cdf_FreeMemory (visit, NULL);
                return status;
            }
        }
        if (numzEntries > 0) {
            status = ValidateAttributeEntryLink (CDF, fp, num, TRUE, AzEDRhead,
                                                 numzEntries, maxzEntry, debug);
            if (status != CDF_OK) {
                cdf_FreeMemory (visit, NULL);
                return status;
            }
        }
        visit[num] = 1;
        offset = nextADR;
    }
    for (ix = 0; ix < GDR.NumAttr; ++ix) {
        if (visit[ix] == 0) {
            cdf_FreeMemory (visit, NULL);
            return QuitCDF ("CDF: an attribute unreachable in attribute link: ",
                            4, 1, &ix, 0, debug);
        }
    }
    cdf_FreeMemory (visit, NULL);
    return CDF_OK;
}
Ejemplo n.º 2
0
static CDFstatus ValidateADR (struct CDFstruct *CDF, vFILE *fp, OFF_T offset,
                              Logical debug)
{
    struct ADRstruct64 ADR;
    CDFstatus status;

    if (debug)
#if defined(win32) || defined(__MINGW32__)
        printf("  Checking ADR...@%I64d\n", offset);
#else
        printf("  Checking ADR...@%lld\n", offset);
#endif
    status = ReadADR64 (fp, offset,
                        ADR_RECORD, &ADR,
                        ADR_NULL);
    if (status != CDF_OK) return status;
    if (ADR.RecordType != ADR_)
        return QuitCDF ("CDF(ADR): record type is invalid ", offset,
                        4, 1, &(ADR.RecordType), 0, debug);
    if (ADR.RecordSize < ADR_BASE_SIZE64 ||
            ADR.RecordSize > ADR_MAX_SIZE64)
        return QuitCDF ("CDF(ADR): record size is invalid ", offset,
                        8, 1, &(ADR.RecordSize), 0, debug);
    if (ADR.ADRnext < 0 || ((ADR.Num < (GDR.NumAttr-1))  && ADR.ADRnext == 0))
        return QuitCDF ("CDF(ADR): offset to next ADR is invalid ", offset,
                        8, 1, &(ADR.ADRnext), 0, debug);
    if (ADR.AgrEDRhead < 0 || (ADR.NgrEntries > 0 && ADR.AgrEDRhead == 0))
        return QuitCDF ("CDF(ADR): offset to AgrEDR is invalid ", offset,
                        8, 1, &(ADR.AgrEDRhead), 0, debug);
    if (!ValidAttrScope(ADR.Scope))
        return QuitCDF ("CDF(ADR): scope is invalid ", offset,
                        4, 1, &(ADR.Scope), 0, debug);
    if (ADR.Num < 0 || ADR.Num > GDR.NumAttr)
        return QuitCDF ("CDF(ADR): attribute number is invalid ", offset,
                        4, 2, &(ADR.Num), &(GDR.NumAttr), debug);
    if (ADR.NgrEntries < 0)
        return QuitCDF ("CDF(ADR): number of g/rEntries is invalid ", offset,
                        4, 1, &(ADR.NgrEntries), 0, debug);
    if (ADR.MAXgrEntry < -1)
        return QuitCDF ("CDF(ADR): max g/rEntry is invalid ", offset,
                        4, 1, &(ADR.MAXgrEntry), 0, debug);
    if ((ADR.Scope == VARIABLE_SCOPE) && (ADR.MAXgrEntry < (ADR.NgrEntries-1)))
        return QuitCDF ("CDF(ADR): max rEntry is invalid ", offset,
                        4, 2, &(ADR.MAXgrEntry), &(ADR.NgrEntries), debug);
    if (ADR.AzEDRhead < 0 || (ADR.NzEntries > 0 && ADR.AzEDRhead == 0))
        return QuitCDF ("CDF(ADR): offset to next AzEDR is invalid ", offset,
                        8, 1, &(ADR.AzEDRhead), 0, debug);
    if ((ADR.Scope == VARIABLE_SCOPE) && (ADR.MAXzEntry < (ADR.NzEntries-1)))
        return QuitCDF ("CDF(ADR): max zEntry is invalid ", offset,
                        4, 2, &(ADR.MAXzEntry), &(ADR.NzEntries), debug);
    if (!ValidAttrName(ADR.Name))
        return QuitCDF ("CDF(ADR): attribute name is invalid ",  offset,
                        0, 1, ADR.Name, 0, debug);
    return CDF_OK;
}