Esempio n. 1
0
        Channel TIDELog::writeCHAN(const std::string& name, const std::string& type, const std::string& source,
                const Array& source_spec, const Array& fmt_spec) {
            // argument checking
            check_bounds("name", 256, name.length());
            check_bounds("type", 10, type.length());
            check_bounds("source", 256, source.length());
            check_bounds("source_spec", 256, source_spec.length);
            check_bounds("fmt_spec", UINT_MAX, fmt_spec.length);

            // header
            HEADER hdr(TAG_CHAN, 4 + 1 + name.length() + type.length() + 4 + 
                        source.length() + 4 + source_spec.length + 4 + fmt_spec.length + 4);

            write_checked<HEADER,HDR_SIZE>(hdr);

            // ID
            const uint32_t id = ++num_chans;
            check_io(1, fwrite(&id, sizeof(id), 1, logfile), "id");
            // name
            write_checked(SArray(name.c_str(), name.length()), "name");
            // type
            write_checked(Array(type.c_str(), type.length()), "type");
            // human-readable source description
            write_checked(Array(source.c_str(), source.length()), "source");
            // source string
            write_checked(source_spec, "spec");
            // format spec
            write_checked(fmt_spec, "format");

            fflush(logfile);

            return Channel(id, name, type, source, source_spec, fmt_spec);
        }
char* test_check_bounds(){
	char* example_str = "this is a test sentence composed of words.";
	char* a = (char*)example_str+5;
	char* b = (char*)example_str+33;
	mu_assert(check_bounds(example_str, a, b), "check_bounds incorrectly classified the given string as invalid.");
	a = (char*)example_str+15;
	b = (char*)example_str+10;
	mu_assert(!check_bounds(example_str, a, b), "check_bounds incorrectly classified the given string as valid.");
	return NULL;
}
Esempio n. 3
0
void machine_t::instr_jmp()
{
  /*
   * This function is not primitive.
   * If we have e.g. JZ, we can always
   * do "0 JZ" to perform the jump.
   *
   * (Note that this will break the
   * HALT-idiom)
   *
   */

  // TODO: Implement as library function

  //push(0);
  //instr_jz();

  int32_t a = pop();
  check_bounds(a, "JMP");  

  // check if we are halting, i.e. jumping to current
  // address -- if so, quit
  if ( a == ip )
    running = false;
  else
    ip = a;
}
Esempio n. 4
0
void machine_t::instr_jnz()
{
  /*
   * Only one of JNZ and JZ is needed as
   * a primitive -- one can be implemented
   * in terms of the other with a negation
   * of the TOS.
   *
   * (Note that this will break the HALT-idiom)
   */

  /*
  instr_puship();
  instr_compl();
  instr_popip();
  instr_jz();
  */

  int32_t a = pop();
  int32_t b = pop();

  if ( a == 0 )
    next();
  else {
    check_bounds(b, "JNZ");
    ip = b; // jump
  }
}
Esempio n. 5
0
void machine_t::instr_stor()
{
  int32_t a = pop();
  check_bounds(a, "STOR");
  memory[a] = pop();
  next();
}
Esempio n. 6
0
T &RowMatrix<T>::ref(size_type i, size_type j)
{
	check_bounds(i, j);

	auto &row_data = m_storage[i];
	size_type left = row_left(i);
	size_type right = row_right(i);

	if (row_data.empty()) {
		// Initialize row if empty.
		row_data.resize(1, static_cast<T>(0));
		left = j;
	} else if (j < left) {
		// Zero-extend row on the left.
		row_data.insert(row_data.begin(), left - j, static_cast<T>(0));
		left = j;
	} else if (j >= right) {
		// Zero-extend row on the right.
		row_data.insert(row_data.end(), j - right + 1, static_cast<T>(0));
	}

	// Update offset array.
	m_offsets[i] = left;

	return row_data[j - left];
}
Esempio n. 7
0
File: pfilter.c Progetto: BobBall/sm
static void adjust_action(action_t new_action)
{
    int skip = 0;

    DEBUG("adjust action=%s, mode=%s\n", 
           action_string[new_action], mode_string[mode]);
    switch (new_action) {
        case ACTION_INCREMENT:
            if (mode == DROP_PERCENT)     drop_percent++;
            else if (mode == DROP_PACKET) drop_packet++;
            else skip = 1;
            break;
        case ACTION_DECREMENT:
            if (mode == DROP_PERCENT)     drop_percent--;
            else if (mode == DROP_PACKET) drop_packet--;
            else skip = 1;
            break;
        case ACTION_ALLOW_ALL:
        case ACTION_DISALLOW_ALL:
            break;
            break;
        case ACTION_RESET_PACKET_COUNT:
            if (mode == DROP_PACKET) curr_packet_count = 0;
            else skip = 1;
            break;
        default:
            assert(0);
    }

    if (!skip) {
            check_bounds();
            last_action = new_action;
            trace_adjustment();
    }
}
Esempio n. 8
0
/**
 * lw6ldr_resampler_source2target
 *
 * @sys_context: global system context
 * @resample: resampler to use
 * @target_x: target x coordinate (out param)
 * @target_y: target y coordinate (out param)
 * @source_x: source x coordinate (in param)
 * @source_y: source y coordinate (in param)
 *
 * Transforms from source coordinate to target coordinates.
 * Does rounding fine-tuning, it's not a simple integer division.
 *
 * Return value: none.
 */
void
lw6ldr_resampler_source2target (lw6sys_context_t * sys_context, const lw6ldr_resampler_t * resampler, int *target_x, int *target_y, int source_x, int source_y)
{
  (*target_x) = (int) (floor ((((float) source_x) + _RESAMPLER_05) * resampler->scale_x));
  (*target_y) = (int) (floor ((((float) source_y) + _RESAMPLER_05) * resampler->scale_y));
  check_bounds (target_x, target_y, resampler->target_w, resampler->target_h);
}
Esempio n. 9
0
/**
 * lw6ldr_resampler_target2source
 *
 * @sys_context: global system context
 * @resample: resampler to use
 * @source_x: source x coordinate (out param)
 * @source_y: source y coordinate (out param)
 * @target_x: target x coordinate (in param)
 * @target_y: target y coordinate (in param)
 *
 * Transforms from target coordinate to source coordinates.
 * Yes, target to source. Target is our final logical map,
 * source is what we loaded from disk, here we want to know,
 * given a point in the target, where to fetch its data from source.
 * Does rounding fine-tuning, it's not a simple integer division.
 *
 * Return value: none.
 */
void
lw6ldr_resampler_target2source (lw6sys_context_t * sys_context, const lw6ldr_resampler_t * resampler, int *source_x, int *source_y, int target_x, int target_y)
{
  (*source_x) = (int) (floor ((((float) target_x) + _RESAMPLER_05) / resampler->scale_x));
  (*source_y) = (int) (floor ((((float) target_y) + _RESAMPLER_05) / resampler->scale_y));
  check_bounds (source_x, source_y, resampler->source_w, resampler->source_h);
}
Esempio n. 10
0
void handle_list
(  mclx*    mx
,  mcxTing* sa
)
   {  mcxKV* kv = tab_g ? mcxHashSearch(sa, hsh_g, MCX_DATUM_FIND) : NULL
   ;  mcxstatus status  = STATUS_OK
   ;  long idx = -1
   ;  if (tab_g && !kv)
      {  label_not_found(sa)
      ;  return
   ;  }
      else if (kv)
      idx = VOID_TO_ULONG kv->val
   ;  else
      status = mcxStrTol(sa->str, &idx, NULL)

   ;  if (status || check_bounds(mx, idx))
      return

   ;  {  mclv* vec = mx->cols+idx
      ;  dim t
      ;  for (t=0;t<vec->n_ivps;t++)
         {  const char* s = tab_g ? mclTabGet(tab_g, (long) vec->ivps[t].idx, NULL) : NULL
         ;  if (s)
            fprintf(stderr, "   %s\n", s)
         ;  else
            fprintf(stderr, "%12ld\n", (long) vec->ivps[t].idx)
      ;  }
      }
   }
Esempio n. 11
0
void overlayData (nvMapGL *map, OPTIONS *options, MISC *misc)
{
  //  Show the filter masked points if any are present.

  if (misc->filter_mask)
    {
      QColor mask = options->marker_color;
      mask.setAlpha (64);

      for (NV_INT32 i = 0 ; i < misc->abe_share->point_cloud_count ; i++)
        {
          //  If we are displaying and editing only a single line, only get those points that 
          //  are in that line.

          if (!misc->num_lines || check_line (misc, misc->data[i].line))
            {
              if (!check_bounds (options, misc, i, NVTrue, misc->slice))
                {
                  if (misc->data[i].fmask)
                    {
                      NV_INT32 pix_x, pix_y;
                      map->get2DCoords (misc->data[i].x, misc->data[i].y, -misc->data[i].z, &pix_x, &pix_y);

                      map->drawLine (pix_x - 3, pix_y - 3, pix_x + 3, pix_y - 3, mask, 2, Qt::SolidLine, NVFalse);
                      map->drawLine (pix_x + 3, pix_y - 3, pix_x + 3, pix_y + 3, mask, 2, Qt::SolidLine, NVFalse);
                      map->drawLine (pix_x + 3, pix_y + 3, pix_x - 3, pix_y + 3, mask, 2, Qt::SolidLine, NVFalse);
                      map->drawLine (pix_x - 3, pix_y + 3, pix_x - 3, pix_y - 3, mask, 2, Qt::SolidLine, NVFalse);
                    }
                }
            }
        }
      map->drawLine (0, 0, 0, 0, options->background_color, 0, Qt::SolidLine, NVTrue);
    }
}
Esempio n. 12
0
void icode_generator::insert_line_marker(void)
{
	//this process cannot support any kind of errors
	if(HccErrorManager::errorCount() > 0)
		return;

	wchar_t last_code;
	cursor -= sizeof(wchar_t);
	memcpy(&last_code, cursor, sizeof(wchar_t));

	HCC_TOKEN_TYPE token_type = HCC_LINE_MARKER;
	check_bounds(sizeof(wchar_t) + sizeof(int));
	//insert the line marker, and the line number...
	wchar_t code = token_type;
	memcpy(cursor, &code, sizeof(wchar_t));
	cursor += sizeof(wchar_t);
	//get the current line number from the source buffer object...
	if(source_ptr!=NULL)
		line_number = source_ptr->lineNumber();
	//
	memcpy(cursor, &line_number, sizeof(int));
	cursor += sizeof(int);

	//insert the last token code...
	memcpy(cursor, &last_code, sizeof(wchar_t));
	cursor += sizeof(wchar_t);
}
Esempio n. 13
0
void machine_t::instr_load()
{
  int32_t a = pop();
  check_bounds(a, "LOAD");
  push(memory[a]);
  next();
}
Esempio n. 14
0
 inline bool
 check_bounds(const matrix_slice<N>& slice, Dims... dims)
 {
   std::size_t indexes[N] {std::size_t(dims)...};
   std::less<std::size_t> lt;
   return std::equal(indexes, indexes + N, slice.extents, lt);
   return check_bounds(slice, indexes);
 }
Esempio n. 15
0
void Histogram::set(int d1, int d2, int d3, PixelType val)
{
	if(check_bounds(d1,d2,d3))
	{
		HistImageType::IndexType index = { { d1, d2, d3 } };
		histImage->SetPixel(index, val);
		//a[d1][d2][d3] = val; 
	}	
}
Esempio n. 16
0
T RowMatrix<T>::val(size_type i, size_type j) const
{
	check_bounds(i, j);

	size_type left = row_left(i);
	size_type right = row_right(i);

	return (j < left || j >= right) ? static_cast<T>(0) : m_storage[i][j - left];
}
Esempio n. 17
0
SEXP c_check_integer(SEXP x, SEXP lower, SEXP upper, SEXP any_missing, SEXP all_missing, SEXP len, SEXP min_len, SEXP max_len, SEXP unique, SEXP names) {
    if (!isInteger(x) && !all_missing_atomic(x))
        return make_type_error(x, "integer");
    assert(check_vector_len(x, len, min_len, max_len));
    assert(check_vector_names(x, names));
    assert(check_vector_missings(x, any_missing, all_missing));
    assert(check_bounds(x, lower, upper));
    assert(check_vector_unique(x, unique));
    return ScalarLogical(TRUE);
}
Esempio n. 18
0
//Get the count at d1,d2,d3
Histogram::PixelType Histogram::v(int d1, int d2, int d3) const
{ 
	if(check_bounds(d1,d2,d3))
	{ 
		HistImageType::IndexType index = { { d1, d2, d3 } };
		return histImage->GetPixel(index);
		//return a[d1][d2][d3]; 
	}
	return 0;
}
Esempio n. 19
0
static void 
pl_check_bounds(Polygon * pl, const vec p)
{
    if (pl->last > 1){
		check_bounds(&pl->bb, p);
    }
    else{
        v_cpy(pl->bb.min, p);
        v_cpy(pl->bb.max, p);
    }
}
Esempio n. 20
0
void machine_t::instr_jz()
{
  int32_t a = pop();
  int32_t b = pop();

  if ( a != 0 )
    next();
  else {
    check_bounds(b, "JZ");
    ip = b; // perform jump
  }
}
Esempio n. 21
0
SEXP c_check_int(SEXP x, SEXP na_ok, SEXP lower, SEXP upper, SEXP tol) {
    Rboolean is_na = is_scalar_na(x);
    double dtol = asNumber(tol, "tol");
    if (xlength(x) != 1 || (!is_na && !isIntegerish(x, dtol)))
        return make_type_error(x, "single integerish value");
    if (is_na) {
        if (!asFlag(na_ok, "na.ok"))
            return make_result("May not be NA");
    }
    assert(check_bounds(x, lower, upper));
    return ScalarLogical(TRUE);
}
Esempio n. 22
0
void icode_generator::append(const Symbol* symbol)
{
	//this process cannot support any kind of errors
	if(HccErrorManager::errorCount() > 0)
		return;
	
	check_bounds(sizeof(int));
	//save this address no matter what symbol table it belongs to...
	int nAddress = reinterpret_cast<int>(symbol);
	memcpy(cursor, &nAddress, sizeof(int));
	cursor += sizeof(int);
}
Esempio n. 23
0
void icode_generator::append(HCC_TOKEN_TYPE type)
{
	assert(type!=HCC_TOKEN_ERROR);
	//this process cannot support any kind of errors
	if(HccErrorManager::errorCount() > 0)
		return;

	wchar_t code = type;
	check_bounds(sizeof(wchar_t));
	memcpy(cursor, &code, sizeof(wchar_t));
	cursor += sizeof(wchar_t);
}
Esempio n. 24
0
static void 
pl_recalc_bounds(Polygon * pl)
{
    assert(pl);
    
    v_cpy(pl->bb.min, pl->points[0].co);
    v_cpy(pl->bb.max, pl->points[0].co);
    
    uint i;
    for (i=1; i < pl->last; i++){
        check_bounds(&pl->bb, pl->points[i].co);
	}
}
Esempio n. 25
0
SEXP c_check_number(SEXP x, SEXP na_ok, SEXP lower, SEXP upper, SEXP finite) {
    Rboolean is_na = is_scalar_na(x);
    if (xlength(x) != 1 || (!is_na && !isStrictlyNumeric(x)))
        return make_type_error(x, "number");
    if (is_na) {
        if (!asFlag(na_ok, "na.ok"))
            return make_result("May not be NA");
        return ScalarLogical(TRUE);
    }
    assert(check_vector_finite(x, finite));
    assert(check_bounds(x, lower, upper));
    return ScalarLogical(TRUE);
}
void
sugar_grid_remove_weight(SugarGrid *grid, GdkRectangle *rect)
{
    int i, k;

    if (!check_bounds(grid, rect)) {
        g_warning("Trying to remove weight outside the grid bounds.");
        return;
    }

    for (k = rect->y; k < rect->y + rect->height; k++) {
        for (i = rect->x; i < rect->x + rect->width; i++) {
            grid->weights[i + k * grid->width] -= 1;
        }
    }
}
Esempio n. 27
0
bool Flasher_::write(PageID page, volatile const Data *bufp) {

  R2P_ASSERT(is_aligned(const_cast<const Data *>(bufp)));

  if (!check_bounds(address_of(page), PAGE_SIZE, get_program_start(),
                    get_program_length())) {
    return false;
  }

  volatile Data *const flashp = reinterpret_cast<volatile Data *>(
    reinterpret_cast<uintptr_t>(address_of(page))
  );

  chSysDisable();

  // Unlock flash for write access
  if (!flash_unlock()) {
    flash_lock();
    chSysEnable();
    return false;
  }
  flash_busy_wait();

  for (size_t pos = 0; pos < PAGE_SIZE / WORD_ALIGNMENT; ++pos) {
    // Enter flash programming mode
    FLASH->CR |= FLASH_CR_PG;

    // Write half-word to flash
    flashp[pos] = bufp[pos];
    flash_busy_wait();

    // Exit flash programming mode
    FLASH->CR &= ~FLASH_CR_PG;

    // Check for flash error
    if (flashp[pos] != bufp[pos]) {
      flash_lock();
      chSysEnable();
      return false;
    }
  }

  flash_lock();
  chSysEnable();
  return true;

}
guint
sugar_grid_compute_weight(SugarGrid *grid, GdkRectangle *rect)
{
    int i, k, sum = 0;

    if (!check_bounds(grid, rect)) {
        g_warning("Trying to compute weight outside the grid bounds.");
        return 0;
    }

    for (k = rect->y; k < rect->y + rect->height; k++) {
        for (i = rect->x; i < rect->x + rect->width; i++) {
            sum += grid->weights[i + k * grid->width];
        }
    }

    return sum;
}
Esempio n. 29
0
//Increment the count at (d1,d2,d3)
void Histogram::inc_element(int d1, int d2, int d3)
{ 
	if(check_bounds(d1,d2,d3))
	{
		HistImageType::IndexType index = { { d1, d2, d3 } };
		PixelType val = histImage->GetPixel(index);
		//if ( a[d1][d2][d3] >= LONG_MAX )
		if( val >= LONG_MAX )
		{ 
			std::cerr<<"Histogram increment overflow!!!"; 
		}
		else
		{ 
			histImage->SetPixel(index, val+inc_scale);
			//a[d1][d2][d3] += inc_scale; 
		}
	}
}
Esempio n. 30
0
void handle_clcf
(  mclx*    mx
,  mcxTing* sa
)
   {  mcxKV* kv = tab_g ? mcxHashSearch(sa, hsh_g, MCX_DATUM_FIND) : NULL
   ;  long idx = -1
   ;  mcxstatus status = STATUS_OK

   ;  if (tab_g && !kv)
      {  label_not_found(sa)
      ;  return
   ;  }
      else if (kv)
      idx = VOID_TO_ULONG kv->val
   ;  else
      status = mcxStrTol(sa->str, &idx, NULL)

   ;  if (status || check_bounds(mx, idx))
      return

   ;  {  double clcf = mclnCLCF(mx, mx->cols+idx, NULL)
      ;  fprintf(stderr, "%.3f\n", clcf)
   ;  }
   }