예제 #1
0
static DWORD
VMCABackupFiles(
    PCSTR pszBaseFilePath
    )
{
    DWORD dwError = ERROR_SUCCESS;
    const DWORD MAX_NUMBER_OF_BAKUPS = 32;
    struct STAT st = { 0 };
    DWORD dwCounter;

    PSTR pszDestFile = NULL;
    PSTR pszSourceFile = NULL;

    for (dwCounter = MAX_NUMBER_OF_BAKUPS; dwCounter > 0; --dwCounter)
    {
        dwError = VMCAAllocateStringPrintfA(
                              &pszDestFile,
                              "%s.%d",
                              pszBaseFilePath,
                              dwCounter);
        BAIL_ON_ERROR(dwError);

        if(STAT(pszDestFile, &st) == ERROR_SUCCESS ) 
        {
            UNLINK(pszDestFile);
        }

        dwError = VMCAAllocateStringPrintfA(
                              &pszSourceFile,
                              "%s.%d",
                              pszBaseFilePath,
                              dwCounter - 1);
        BAIL_ON_ERROR(dwError);

        RENAME(pszSourceFile, pszDestFile);

        VMCA_SAFE_FREE_STRINGA(pszDestFile);
        VMCA_SAFE_FREE_STRINGA(pszSourceFile);

        pszDestFile = NULL;
        pszSourceFile = NULL;
    }

    VMCA_SAFE_FREE_STRINGA(pszDestFile);

    dwError = VMCAAllocateStringPrintfA(
                          &pszDestFile,
                          "%s.%d",
                          pszBaseFilePath,
                          0);
    BAIL_ON_ERROR(dwError);

    RENAME(pszBaseFilePath, pszDestFile);

error:
    VMCA_SAFE_FREE_STRINGA(pszDestFile);
    VMCA_SAFE_FREE_STRINGA(pszSourceFile);

    return dwError;
}
void CWE252_Unchecked_Return_Value__char_rename_12_bad()
{
    if(globalReturnsTrueOrFalse())
    {
        /* FLAW: Do not check the return value */
        RENAME(OLD_BAD_FILE_NAME, "newbadfilename.txt");
    }
    else
    {
        /* FIX: check the return value */
        if (RENAME(OLD_GOOD_FILE_NAME, "newgoodfilename.txt") != 0)
        {
            printLine("rename failed!");
        }
    }
}
예제 #3
0
static RENAME(mix_any_func_type) *RENAME(get_mix_any_func)(SwrContext *s){
    if(   s->out_ch_layout == AV_CH_LAYOUT_STEREO && (s->in_ch_layout == AV_CH_LAYOUT_5POINT1 || s->in_ch_layout == AV_CH_LAYOUT_5POINT1_BACK)
       && s->matrix[0][2] == s->matrix[1][2] && s->matrix[0][3] == s->matrix[1][3]
       && !s->matrix[0][1] && !s->matrix[0][5] && !s->matrix[1][0] && !s->matrix[1][4]
    )
        return RENAME(mix6to2);

    if(   s->out_ch_layout == AV_CH_LAYOUT_STEREO && s->in_ch_layout == AV_CH_LAYOUT_7POINT1
       && s->matrix[0][2] == s->matrix[1][2] && s->matrix[0][3] == s->matrix[1][3]
       && !s->matrix[0][1] && !s->matrix[0][5] && !s->matrix[1][0] && !s->matrix[1][4]
       && !s->matrix[0][7] && !s->matrix[1][6]
    )
        return RENAME(mix8to2);

    return NULL;
}
void CWE252_Unchecked_Return_Value__char_rename_05_bad()
{
    if(staticTrue)
    {
        /* FLAW: Do not check the return value */
        RENAME(OLD_BAD_FILE_NAME, "newbadfilename.txt");
    }
}
void CWE252_Unchecked_Return_Value__wchar_t_rename_10_bad()
{
    if(globalTrue)
    {
        /* FLAW: Do not check the return value */
        RENAME(OLD_BAD_FILE_NAME, L"newbadfilename.txt");
    }
}
static void good1()
{
    /* FIX: check the return value */
    if (RENAME(OLD_GOOD_FILE_NAME, "newgoodfilename.txt") != 0)
    {
        printLine("rename failed!");
    }
}
void CWE252_Unchecked_Return_Value__char_rename_13_bad()
{
    if(GLOBAL_CONST_FIVE==5)
    {
        /* FLAW: Do not check the return value */
        RENAME(OLD_BAD_FILE_NAME, "newbadfilename.txt");
    }
}
예제 #8
0
파일: minips.cpp 프로젝트: endriff/sam2p
void MiniPS::Dict::getNext (char const*const*& key, slen_t &keylen, VALUE *&val, bool &touched) {
  val+=2;
  if (len+(VALUE*)ptr==(VALUE*)val-1) { key=(char const*const*)NULLP; return; }
  Ename *skey=RENAME(val[-1]&~1);
  // assert(MiniPS::getType((VALUE)skey)==T_ENAME);
  key=(char**)&skey->ptr;
  keylen=skey->len;
  touched=(val[-1]&1)!=0;
}
예제 #9
0
파일: gtm_rename.c 프로젝트: 5HT/mumps
uint4 gtm_rename(char *org_fn, int org_fn_len, char *rename_fn, int rename_len, uint4 *ustatus)
{
	*ustatus = SS_NORMAL;	/* used in VMS only */
	assert(0 == org_fn[org_fn_len]);
	assert(0 == rename_fn[rename_len]);
	if (-1 == RENAME(org_fn, rename_fn))
		return errno;
	return SS_NORMAL;
}
/* good1() uses the GoodSink on both sides of the "if" statement */
static void good1()
{
    if(globalReturnsTrueOrFalse())
    {
        /* FIX: check the return value */
        if (RENAME(OLD_GOOD_FILE_NAME, "newgoodfilename.txt") != 0)
        {
            printLine("rename failed!");
        }
    }
    else
    {
        /* FIX: check the return value */
        if (RENAME(OLD_GOOD_FILE_NAME, "newgoodfilename.txt") != 0)
        {
            printLine("rename failed!");
        }
    }
}
/* good2() reverses the bodies in the if statement */
static void good2()
{
    if(globalFive==5)
    {
        /* FIX: check the return value */
        if (RENAME(OLD_GOOD_FILE_NAME, L"newgoodfilename.txt") != 0)
        {
            printLine("rename failed!");
        }
    }
}
/* good2() reverses the bodies in the if statement */
static void good2()
{
    if(globalFive==5)
    {
        /* FIX: check for the correct return value */
        if (RENAME(OLD_GOOD_FILE_NAME, NEW_GOOD_FILE_NAME) != 0)
        {
            printLine("rename failed!");
        }
    }
}
/* good2() reverses the bodies in the if statement */
static void good2()
{
    if(GLOBAL_CONST_FIVE==5)
    {
        /* FIX: check the return value */
        if (RENAME(OLD_GOOD_FILE_NAME, "newgoodfilename.txt") != 0)
        {
            printLine("rename failed!");
        }
    }
}
void CWE253_Incorrect_Check_of_Function_Return_Value__wchar_t_rename_14_bad()
{
    if(globalFive==5)
    {
        /* FLAW: rename() might fail, in which case the return value will be non-zero, but
         * we are checking to see if the return value is 0 */
        if (RENAME(OLD_BAD_FILE_NAME, NEW_BAD_FILE_NAME) == 0)
        {
            printLine("rename failed!");
        }
    }
}
/* good1() uses the GoodSinkBody in the for statements */
static void good1()
{
    int k;
    for(k = 0; k < 1; k++)
    {
        /* FIX: check for the correct return value */
        if (RENAME(OLD_GOOD_FILE_NAME, NEW_GOOD_FILE_NAME) != 0)
        {
            printLine("rename failed!");
        }
    }
}
void INITIALIZE()
{
  SHOW_PROGRESS(1);
   
  COPY_FILE_HERE("MIUI_DHD_ROM\\MIUI.zip");   /* move MIUI.zip to work dic */
  
  RENAME("MIUI.zip","temp.zip");
  
  _7zUNPACK("temp.zip");
  
  DELETE_FILE("temp.zip");  
}
예제 #17
0
static av_always_inline void RENAME(horizontal_compose_haari)(TYPE *b, TYPE *temp,
                                                              int w, int shift)
{
    const int w2 = w >> 1;
    int x;

    for (x = 0; x < w2; x++) {
        temp[x   ] = COMPOSE_HAARiL0(b[x   ], b[x+w2]);
        temp[x+w2] = COMPOSE_HAARiH0(b[x+w2], temp[x]);
    }

    RENAME(interleave)(b, temp, temp+w2, w2, shift, shift);
}
예제 #18
0
static void RENAME(decode_rgb_frame)(FFV1Context *s, uint8_t *src[3], int w, int h, int stride[3])
{
    int x, y, p;
    TYPE *sample[4][2];
    int lbd    = s->avctx->bits_per_raw_sample <= 8;
    int bits   = s->avctx->bits_per_raw_sample > 0 ? s->avctx->bits_per_raw_sample : 8;
    int offset = 1 << bits;

    for (x = 0; x < 4; x++) {
        sample[x][0] = RENAME(s->sample_buffer) +  x * 2      * (w + 6) + 3;
        sample[x][1] = RENAME(s->sample_buffer) + (x * 2 + 1) * (w + 6) + 3;
    }

    s->run_index = 0;

    memset(RENAME(s->sample_buffer), 0, 8 * (w + 6) * sizeof(*RENAME(s->sample_buffer)));

    for (y = 0; y < h; y++) {
        for (p = 0; p < 3 + s->transparency; p++) {
            TYPE *temp = sample[p][0]; // FIXME: try a normal buffer

            sample[p][0] = sample[p][1];
            sample[p][1] = temp;

            sample[p][1][-1]= sample[p][0][0  ];
            sample[p][0][ w]= sample[p][0][w-1];
            if (lbd && s->slice_coding_mode == 0)
                RENAME(decode_line)(s, w, sample[p], (p + 1)/2, 9);
            else
                RENAME(decode_line)(s, w, sample[p], (p + 1)/2, bits + (s->slice_coding_mode != 1));
        }
        for (x = 0; x < w; x++) {
            int g = sample[0][1][x];
            int b = sample[1][1][x];
            int r = sample[2][1][x];
            int a = sample[3][1][x];

            if (s->slice_coding_mode != 1) {
                b -= offset;
                r -= offset;
                g -= (b * s->slice_rct_by_coef + r * s->slice_rct_ry_coef) >> 2;
                b += g;
                r += g;
            }

            if (lbd)
                *((uint32_t*)(src[0] + x*4 + stride[0]*y)) = b + ((unsigned)g<<8) + ((unsigned)r<<16) + ((unsigned)a<<24);
            else if (sizeof(TYPE) == 4) {
                *((uint16_t*)(src[0] + x*2 + stride[0]*y)) = g;
                *((uint16_t*)(src[1] + x*2 + stride[1]*y)) = b;
                *((uint16_t*)(src[2] + x*2 + stride[2]*y)) = r;
            } else {
                *((uint16_t*)(src[0] + x*2 + stride[0]*y)) = b;
                *((uint16_t*)(src[1] + x*2 + stride[1]*y)) = g;
                *((uint16_t*)(src[2] + x*2 + stride[2]*y)) = r;
            }
        }
    }
예제 #19
0
int32_t CTB_rename(char *new_name, char *old_name)
{
    char newname[MAXPATH], oldname[MAXPATH];

    if (*(new_name + 1) != ':' && *(old_name + 1) != ':' || // without disk names //
            toupper(*new_name) == toupper(*old_name) && *(new_name + 1) == ':'
            && *(old_name + 1) == ':') { // one disk           //
        char *p = ctb_last_punct(old_name);

        if (p)
            *p = 0;

        p = ctb_last_punct(new_name);

        if (p)
            *p = 0;

        SPRINTF(newname, "%s.CTB", new_name);
        SPRINTF(oldname, "%s.CTB", old_name);

        if (!access(newname, 0))
            unlink(newname);

        RENAME(oldname, newname); // two files in one disk  //
        SPRINTF(newname, "%s.IND", new_name);
        SPRINTF(oldname, "%s.IND", old_name);

        if (!access(newname, 0))
            unlink(newname);

        RENAME(oldname, newname); // two files in one disk  //
        return 1;
    }

    CTB_move(new_name, old_name); // move from disk to disk //
    return 2;
}
/* good1() uses if(globalFive!=5) instead of if(globalFive==5) */
static void good1()
{
    if(globalFive!=5)
    {
        /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */
        printLine("Benign, fixed string");
    }
    else
    {
        /* FIX: check for the correct return value */
        if (RENAME(OLD_GOOD_FILE_NAME, NEW_GOOD_FILE_NAME) != 0)
        {
            printLine("rename failed!");
        }
    }
}
예제 #21
0
static void RENAME(horizontal_compose_dirac53i)(uint8_t *_b, uint8_t *_temp, int w)
{
    int x;
    const int w2 = w >> 1;
    TYPE *b     = (TYPE *)_b;
    TYPE *temp  = (TYPE *)_temp;

    temp[0] = COMPOSE_53iL0(b[w2], b[0], b[w2]);
    for (x = 1; x < w2; x++) {
        temp[x     ] = COMPOSE_53iL0     (b[x+w2-1], b[x     ], b[x+w2]);
        temp[x+w2-1] = COMPOSE_DIRAC53iH0(temp[x-1], b[x+w2-1], temp[x]);
    }
    temp[w-1] = COMPOSE_DIRAC53iH0(temp[w2-1], b[w-1], temp[w2-1]);

    RENAME(interleave)(b, temp, temp+w2, w2, 1, 1);
}
/* good1() uses if(GLOBAL_CONST_FIVE!=5) instead of if(GLOBAL_CONST_FIVE==5) */
static void good1()
{
    if(GLOBAL_CONST_FIVE!=5)
    {
        /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */
        printLine("Benign, fixed string");
    }
    else
    {
        /* FIX: check the return value */
        if (RENAME(OLD_GOOD_FILE_NAME, "newgoodfilename.txt") != 0)
        {
            printLine("rename failed!");
        }
    }
}
/* good2() reverses the blocks in the switch */
static void good2()
{
    switch(6)
    {
    case 6:
        /* FIX: check for the correct return value */
        if (RENAME(OLD_GOOD_FILE_NAME, NEW_GOOD_FILE_NAME) != 0)
        {
            printLine("rename failed!");
        }
        break;
    default:
        /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */
        printLine("Benign, fixed string");
        break;
    }
}
void CWE253_Incorrect_Check_of_Function_Return_Value__char_rename_15_bad()
{
    switch(6)
    {
    case 6:
        /* FLAW: rename() might fail, in which case the return value will be non-zero, but
         * we are checking to see if the return value is 0 */
        if (RENAME(OLD_BAD_FILE_NAME, NEW_BAD_FILE_NAME) == 0)
        {
            printLine("rename failed!");
        }
        break;
    default:
        /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */
        printLine("Benign, fixed string");
        break;
    }
}
예제 #25
0
void
writelast()
{
    sprintf(buf,"%s.%ld", lastfile, our_pid);
    if ((tmpfp = fopen(buf,"w")) != NULL) {
	if (lasttime < starttime)
	    lasttime = starttime;
	fprintf(tmpfp,"%s\n%ld\n%ld\n%ld\n%ld\n",
		ngname? ngname : nullstr,lasttime,
		lastactsiz,lastnewtime,lastextranum);
	fclose(tmpfp);
	UNLINK(lastfile);
	RENAME(buf,lastfile);
    }
    else {
	printf(cantcreate,buf) FLUSH;
	/*termdown(1);*/
    }
}
예제 #26
0
static void RENAME(horizontal_compose_fidelityi)(uint8_t *_b, uint8_t *_tmp, int w)
{
    const int w2 = w >> 1;
    int i, x;
    TYPE v[8];
    TYPE *b   = (TYPE *)_b;
    TYPE *tmp = (TYPE *)_tmp;

    for (x = 0; x < w2; x++) {
        for (i = 0; i < 8; i++)
            v[i] = b[av_clip(x-3+i, 0, w2-1)];
        tmp[x] = COMPOSE_FIDELITYiH0(v[0], v[1], v[2], v[3], b[x+w2], v[4], v[5], v[6], v[7]);
    }

    for (x = 0; x < w2; x++) {
        for (i = 0; i < 8; i++)
            v[i] = tmp[av_clip(x-4+i, 0, w2-1)];
        tmp[x+w2] = COMPOSE_FIDELITYiL0(v[0], v[1], v[2], v[3], b[x], v[4], v[5], v[6], v[7]);
    }

    RENAME(interleave)(b, tmp+w2, tmp, w2, 0, 0);
}
예제 #27
0
static int RENAME(ff_spatial_idwt_init)(DWTContext *d, enum dwt_type type)
{
    int level;

    d->temp = (uint8_t *)(((TYPE *)d->temp) + 8);

    for (level = d->decomposition_count - 1; level >= 0; level--){
        int hl = d->height >> level;
        int stride_l = d->stride << level;

        switch(type){
            case DWT_DIRAC_DD9_7:
                RENAME(spatial_compose_dd97i_init)(d->cs+level, d->buffer, hl, stride_l);
                break;
            case DWT_DIRAC_LEGALL5_3:
                RENAME(spatial_compose53i_init)(d->cs+level, d->buffer, hl, stride_l);
                break;
            case DWT_DIRAC_DD13_7:
                RENAME(spatial_compose_dd137i_init)(d->cs+level, d->buffer, hl, stride_l);
                break;
            case DWT_DIRAC_HAAR0:
            case DWT_DIRAC_HAAR1:
                d->cs[level].y = 1;
                break;
            case DWT_DIRAC_DAUB9_7:
                RENAME(spatial_compose97i_init)(d->cs+level, d->buffer, hl, stride_l);
                break;
            default:
                d->cs[level].y = 0;
                break;
        }
    }

    switch (type) {
        case DWT_DIRAC_DD9_7:
            d->spatial_compose = RENAME(spatial_compose_dd97i_dy);
            d->vertical_compose_l0 = (void*)RENAME(vertical_compose53iL0);
            d->vertical_compose_h0 = (void*)RENAME(vertical_compose_dd97iH0);
            d->horizontal_compose = RENAME(horizontal_compose_dd97i);
            d->support = 7;
            break;
        case DWT_DIRAC_LEGALL5_3:
            d->spatial_compose = RENAME(spatial_compose_dirac53i_dy);
            d->vertical_compose_l0 = (void*)RENAME(vertical_compose53iL0);
            d->vertical_compose_h0 = (void*)RENAME(vertical_compose_dirac53iH0);
            d->horizontal_compose = RENAME(horizontal_compose_dirac53i);
            d->support = 3;
            break;
        case DWT_DIRAC_DD13_7:
            d->spatial_compose = RENAME(spatial_compose_dd137i_dy);
            d->vertical_compose_l0 = (void*)RENAME(vertical_compose_dd137iL0);
            d->vertical_compose_h0 = (void*)RENAME(vertical_compose_dd97iH0);
            d->horizontal_compose = RENAME(horizontal_compose_dd137i);
            d->support = 7;
            break;
        case DWT_DIRAC_HAAR0:
        case DWT_DIRAC_HAAR1:
            d->spatial_compose = RENAME(spatial_compose_haari_dy);
            d->vertical_compose = (void*)RENAME(vertical_compose_haar);
            if (type == DWT_DIRAC_HAAR0)
                d->horizontal_compose = RENAME(horizontal_compose_haar0i);
            else
                d->horizontal_compose = RENAME(horizontal_compose_haar1i);
            d->support = 1;
            break;
        case DWT_DIRAC_FIDELITY:
            d->spatial_compose = RENAME(spatial_compose_fidelity);
            d->vertical_compose_l0 = (void*)RENAME(vertical_compose_fidelityiL0);
            d->vertical_compose_h0 = (void*)RENAME(vertical_compose_fidelityiH0);
            d->horizontal_compose = RENAME(horizontal_compose_fidelityi);
            d->support = 0; // not really used
            break;
        case DWT_DIRAC_DAUB9_7:
            d->spatial_compose = RENAME(spatial_compose_daub97i_dy);
            d->vertical_compose_l0 = (void*)RENAME(vertical_compose_daub97iL0);
            d->vertical_compose_h0 = (void*)RENAME(vertical_compose_daub97iH0);
            d->vertical_compose_l1 = (void*)RENAME(vertical_compose_daub97iL1);
            d->vertical_compose_h1 = (void*)RENAME(vertical_compose_daub97iH1);
            d->horizontal_compose = RENAME(horizontal_compose_daub97i);
            d->support = 5;
            break;
        default:
            return AVERROR_INVALIDDATA;
    }

    return 0;
}
예제 #28
0
/**
 * Handler for RENAME message from client, creates
 * new identity.
 *
 * @param cls unused
 * @param client who sent the message
 * @param message the message received
 */
static void
handle_rename_message (void *cls, struct GNUNET_SERVER_Client *client,
		       const struct GNUNET_MessageHeader *message)
{
  const struct GNUNET_IDENTITY_RenameMessage *rm;
  uint16_t size;
  uint16_t old_name_len;
  uint16_t new_name_len;
  struct Ego *ego;
  const char *old_name;
  const char *new_name;
  struct RenameContext rename_ctx;
  char *fn_old;
  char *fn_new;

  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
	      "Received RENAME message from client\n");
  size = ntohs (message->size);
  if (size <= sizeof (struct GNUNET_IDENTITY_RenameMessage))
  {
    GNUNET_break (0);
    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
    return;
  }
  rm = (const struct GNUNET_IDENTITY_RenameMessage *) message;
  old_name_len = ntohs (rm->old_name_len);
  new_name_len = ntohs (rm->new_name_len);
  old_name = (const char *) &rm[1];
  new_name = &old_name[old_name_len];
  if ( (old_name_len + new_name_len + sizeof (struct GNUNET_IDENTITY_RenameMessage) != size) ||
       ('\0' != old_name[old_name_len - 1]) ||
       ('\0' != new_name[new_name_len - 1]) )
  {
    GNUNET_break (0);
    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
    return;
  }

  /* check if new name is already in use */
  for (ego = ego_head; NULL != ego; ego = ego->next)
  {
    if (0 == strcmp (ego->identifier,
		     new_name))
    {
      send_result_code (client, 1, gettext_noop ("target name already exists"));
      GNUNET_SERVER_receive_done (client, GNUNET_OK);
      return;
    }
  }

  /* locate old name and, if found, perform rename */
  for (ego = ego_head; NULL != ego; ego = ego->next)
  {
    if (0 == strcmp (ego->identifier,
		     old_name))
    {
      fn_old = get_ego_filename (ego);
      GNUNET_free (ego->identifier);
      rename_ctx.old_name = old_name;
      rename_ctx.new_name = new_name;
      GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg,
					     &handle_ego_rename,
					     &rename_ctx);
      if (GNUNET_OK !=
	  GNUNET_CONFIGURATION_write (subsystem_cfg,
				      subsystem_cfg_file))
	GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
		    _("Failed to write subsystem default identifier map to `%s'.\n"),
		    subsystem_cfg_file);
      ego->identifier = GNUNET_strdup (new_name);
      fn_new = get_ego_filename (ego);
      if (0 != RENAME (fn_old, fn_new))
	GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rename", fn_old);
      GNUNET_free (fn_old);
      GNUNET_free (fn_new);
      notify_listeners (ego);
      send_result_code (client, 0, NULL);
      GNUNET_SERVER_receive_done (client, GNUNET_OK);
      return;
    }
  }

  /* failed to locate old name */
  send_result_code (client, 1, gettext_noop ("no matching ego found"));
  GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
예제 #29
0
static av_always_inline int RENAME(decode_line)(FFV1Context *s, int w,
                                                 TYPE *sample[2],
                                                 int plane_index, int bits)
{
    PlaneContext *const p = &s->plane[plane_index];
    RangeCoder *const c   = &s->c;
    int x;
    int run_count = 0;
    int run_mode  = 0;
    int run_index = s->run_index;

    if (is_input_end(s))
        return AVERROR_INVALIDDATA;

    if (s->slice_coding_mode == 1) {
        int i;
        for (x = 0; x < w; x++) {
            int v = 0;
            for (i=0; i<bits; i++) {
                uint8_t state = 128;
                v += v + get_rac(c, &state);
            }
            sample[1][x] = v;
        }
        return 0;
    }

    for (x = 0; x < w; x++) {
        int diff, context, sign;

        if (!(x & 1023)) {
            if (is_input_end(s))
                return AVERROR_INVALIDDATA;
        }

        context = RENAME(get_context)(p, sample[1] + x, sample[0] + x, sample[1] + x);
        if (context < 0) {
            context = -context;
            sign    = 1;
        } else
            sign = 0;

        av_assert2(context < p->context_count);

        if (s->ac != AC_GOLOMB_RICE) {
            diff = get_symbol_inline(c, p->state[context], 1);
        } else {
            if (context == 0 && run_mode == 0)
                run_mode = 1;

            if (run_mode) {
                if (run_count == 0 && run_mode == 1) {
                    if (get_bits1(&s->gb)) {
                        run_count = 1 << ff_log2_run[run_index];
                        if (x + run_count <= w)
                            run_index++;
                    } else {
                        if (ff_log2_run[run_index])
                            run_count = get_bits(&s->gb, ff_log2_run[run_index]);
                        else
                            run_count = 0;
                        if (run_index)
                            run_index--;
                        run_mode = 2;
                    }
                }
                while (run_count > 1 && w-x > 1) {
                    sample[1][x] = RENAME(predict)(sample[1] + x, sample[0] + x);
                    x++;
                    run_count--;
                }
                run_count--;
                if (run_count < 0) {
                    run_mode  = 0;
                    run_count = 0;
                    diff      = get_vlc_symbol(&s->gb, &p->vlc_state[context],
                                               bits);
                    if (diff >= 0)
                        diff++;
                } else
                    diff = 0;
            } else
                diff = get_vlc_symbol(&s->gb, &p->vlc_state[context], bits);

            ff_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n",
                    run_count, run_index, run_mode, x, get_bits_count(&s->gb));
        }

        if (sign)
            diff = -(unsigned)diff;

        sample[1][x] = av_mod_uintp2(RENAME(predict)(sample[1] + x, sample[0] + x) + (SUINT)diff, bits);
    }
    s->run_index = run_index;
    return 0;
}
예제 #30
0
int32_t CTB_compress(const char *filename)
{
    char *p, tmp_file[MAXPATH], file_name[MAXPATH];
    CTB_handle hi, ho;
    int32_t i, n, compress;
    uchar dst[CTB_DATA_SIZE], buffer[256* 128 + 2 + CTB_DATA_SIZE ];
    p = ctb_last_punct(file_name);
    strcpy(file_name, filename);
    ctb_err_code = CTB_ERR_NONE;

    if (p)
        *p = '\0';

    STRCPY(tmp_file, file_name);
    p = STRRCHR(tmp_file, '\\');

    if (p) {
        *(p + 1) = '\0';
        STRCAT(tmp_file, "$$$$$$$$");
    }

    else
        STRCPY(tmp_file, "$$$$$$$$");

    if (!CTB_open(file_name, &hi, "w"))
        return FALSE;

    CTB_read_global_data(&hi, dst);
    CTB_files_init(tmp_file, dst, hi.width, hi.height, hi.dpb, hi.signums,
                   hi.attr_size);
    n = CTB_volume(&hi);
    compress = hi.need_compress;

    if (compress) {
        if (!CTB_open(tmp_file, &ho, "w"))
            return 0;

        for (i = 0; i < n; i++) {
            switch (CTB_read(&hi, i, buffer, dst)) {
                case 1:
                    CTB_write_mark(&ho, -1, buffer, dst, FALSE);
                    break;
                case 2:
                    CTB_write_mark(&ho, -1, buffer, dst, TRUE);
                    break;
                default:
                    break;
            }
        }

        ho.need_compress = 0;
        CTB_close(&ho);
    }

    hi.need_compress = 0;
    CTB_close(&hi);

    if (!compress) { // delete tmp file //
        STRCAT(tmp_file, ".CTB");
        UNLINK(tmp_file);
        *ctb_last_punct(tmp_file) = 0;
        STRCAT(tmp_file, ".IND");
        UNLINK(tmp_file);
        return 0;
    }

    STRCAT(file_name, ".CTB");
    STRCAT(tmp_file, ".CTB");
    UNLINK(file_name);
    RENAME(tmp_file, file_name);
    *ctb_last_punct(tmp_file) = 0;
    *ctb_last_punct(file_name) = 0;
    STRCAT(file_name, ".IND");
    STRCAT(tmp_file, ".IND");
    UNLINK(file_name);
    RENAME(tmp_file, file_name);
    return n;
}