Example #1
0
static int
pop_raw (lw6sys_context_t * sys_context, lw6sys_hexa_serializer_t * hexa_serializer, u_int8_t * buf, int size)
{
  int ret = 0;
  int i;
  int j;
  char hexa2[3] = { 0, 0, 0 };	// third 0 is *very* important

  if (check_size (sys_context, hexa_serializer, size * 2))
    {
      for (i = 0; i < size; ++i, hexa_serializer->pos += 2)
	{
	  j = 0;
	  memcpy (hexa2, hexa_serializer->buf + hexa_serializer->pos, 2);
	  /*
	   * Performing sscanf on long strings is a performance killer
	   * for sscanf calls strlen internally to get the length
	   * of the string...
	   */
	  sscanf (hexa2, "%02x", &j);
	  buf[i] = (u_int8_t) j;
	}
      if (hexa_serializer->pos < hexa_serializer->buf_size && !(hexa_serializer->pos & 0x01))
	{
	  ret = 1;
	}
      else
	{
	  lw6sys_log (sys_context, LW6SYS_LOG_WARNING,
		      _x_ ("inconsistent hexa_serializer after pop, pos=%d, buf_size=%d"), hexa_serializer->pos, hexa_serializer->buf_size);
	}
    }

  return ret;
}
Example #2
0
File: error.c Project: Cmdeew/dante
void	check_tab(char **tab)
{
  if (check_char(tab) == 1)
    put_err("One character is not * or X");
  if (check_size(tab) == 1)
    put_err("The lab is not a rectangle");
}
    vector& operator=(const Src& that) 
    {
	check_size(size(that));
	for (int i= 0; i < my_size; ++i)
	    data[i]= that[i];
	return *this;
    }
Example #4
0
static int
resize (lw6sys_context_t * sys_context, lw6sys_hexa_serializer_t * hexa_serializer, int required)
{
  int ret = 0;
  int new_size = 0;

  if (!check_size (sys_context, hexa_serializer, required))
    {
      new_size = (hexa_serializer->buf_size * RESIZE_FACTOR) + RESIZE_PLUS + required;
      hexa_serializer->buf = LW6SYS_REALLOC (sys_context, hexa_serializer->buf, new_size);
      if (hexa_serializer->buf)
	{
	  hexa_serializer->buf_size = new_size;
	  ret = 1;
	}
      else
	{
	  lw6sys_log (sys_context, LW6SYS_LOG_WARNING, _x_ ("can't resize hexa_serializer (new_size=%d), expect serious trouble"), new_size);
	}
    }
  else
    {
      // nothing to do...
      ret = 1;
    }

  return ret;
}
Example #5
0
static int test_mknod(void)
{
    int err = 0;
    int res;

    start_test("mknod");
    unlink(testfile);
    res = mknod(testfile, 0644, 0);
    if (res == -1) {
        PERROR("mknod");
        return -1;
    }
    res = check_type(testfile, S_IFREG);
    if (res == -1)
        return -1;
    err += check_mode(testfile, 0644);
    err += check_nlink(testfile, 1);
    err += check_size(testfile, 0);
    res = unlink(testfile);
    if (res == -1) {
        PERROR("unlink");
        return -1;
    }
    res = check_nonexist(testfile);
    if (res == -1)
        return -1;
    if (err)
        return -1;

    success();
    return 0;
}
Example #6
0
static int strtab_read(const struct buffer *in, struct parsed_elf *pelf)
{
	Elf64_Ehdr *ehdr;
	Elf64_Word i;

	ehdr = &pelf->ehdr;

	if (ehdr->e_shstrndx >= ehdr->e_shnum) {
		ERROR("Section header string table index out of range: %d\n",
		      ehdr->e_shstrndx);
		return -1;
	}

	/* For each section of type SHT_STRTAB create a symtab buffer. */
	pelf->strtabs = calloc(ehdr->e_shnum, sizeof(struct buffer *));

	for (i = 0; i < ehdr->e_shnum; i++) {
		struct buffer *b;
		Elf64_Shdr *shdr = &pelf->shdr[i];

		if (shdr->sh_type != SHT_STRTAB)
			continue;

		b = calloc(1, sizeof(*b));
		buffer_splice(b, in, shdr->sh_offset, shdr->sh_size);
		if (check_size(in, shdr->sh_offset, buffer_size(b), "strtab")) {
			ERROR("STRTAB section not within bounds: %d\n", i);
			free(b);
			return -1;
		}
		pelf->strtabs[i] = b;
	}

	return 0;
}
Example #7
0
static int
shdr_read(const struct buffer *in, struct parsed_elf *pelf,
          struct xdr *xdr, int bit64)
{
	struct buffer b;
	Elf64_Shdr *shdr;
	Elf64_Ehdr *ehdr;
	int i;

	ehdr = &pelf->ehdr;

	/* cons up an input buffer for the section headers.
	 * Note that the section headers can be anywhere,
	 * per the ELF spec, You'd be surprised how many ELF
	 * readers miss this little detail.
	 */
	buffer_splice(&b, in, ehdr->e_shoff, ehdr->e_shentsize * ehdr->e_shnum);
	if (check_size(in, ehdr->e_shoff, buffer_size(&b), "section headers"))
		return -1;

	/* gather up all the shdrs. */
	shdr = calloc(ehdr->e_shnum, sizeof(*shdr));
	for (i = 0; i < ehdr->e_shnum; i++) {
		DEBUG("Parsing section %d\n", i);
		elf_shdr(&b, &shdr[i], ehdr->e_shentsize, xdr, bit64);
	}

	pelf->shdr = shdr;

	return 0;
}
Example #8
0
static void init_legacy_currval(struct gl_context *ctx)
{
   struct vbo_context *vbo = vbo_context(ctx);
   struct gl_client_array *arrays = vbo->legacy_currval;
   GLuint i;

   memset(arrays, 0, sizeof(*arrays) * VERT_ATTRIB_MAX);

   /* Set up a constant (StrideB == 0) array for each current
    * attribute:
    */
   for (i = 0; i < VERT_ATTRIB_MAX; i++) {
      struct gl_client_array *cl = &arrays[i];

      /* Size will have to be determined at runtime:
       */
      cl->Size = check_size(ctx->Current.Attrib[i]);
      cl->Stride = 0;
      cl->StrideB = 0;
      cl->Enabled = 1;
      cl->Type = GL_FLOAT;
      cl->Ptr = (const void *)ctx->Current.Attrib[i];
      cl->_ElementSize = cl->Size * sizeof(GLfloat);
      _mesa_reference_buffer_object(ctx, &cl->BufferObj,
                                    ctx->Shared->NullBufferObj);
   }
}
Example #9
0
/* Convert a number to a certain radix and send over uart.
 * 32-bit version */
static void norecurse_32(uint32_t input, uint8_t radix)
{  
   uint8_t remainder = input % radix;

   uint8_t *p = charbuff;
   
   buffsize = 0;
   
   if(input == 0)
      charbuff[buffsize++] = '0';   
   
   while(input >= radix) {
      if(remainder <= 9)
	 *p++ = remainder + '0';
      else
	 *p++ = remainder - 10 + 'A';

      buffsize++;
      input /= radix;
      remainder = input % radix;
   }

   if(remainder > 0) {
      if(remainder <= 9)
	 *p++ = remainder + '0';
      else
	 *p++ = remainder - 10 + 'A';
      buffsize++;
   }
   
   // Calculate amount we still need to pad.  We never truncate a result.
   if(fieldwidth > buffsize)
      fieldwidth -= buffsize;
   else
      fieldwidth = 0;
   while(fieldwidth--) {
      printf_packet.data[printf_packet.size++] = padchar;
      check_size();
   }

   
   while(buffsize > 0) {
      buffsize--;
      printf_packet.data[printf_packet.size++] = charbuff[buffsize];
      check_size();
   }
}
    vector operator+( const vector& that ) const 
    {
	check_size(that.my_size);
	vector sum(my_size);
	for (unsigned i= 0; i < my_size; ++i) 
	    sum[i] = data[i] + that[i];
	return sum ;
    }
Example #11
0
SubjectCanvas::SubjectCanvas(UmlCanvas * canvas, int x, int y, int id)
    : DiagramCanvas(0, canvas, x, y, SUBJECT_CANVAS_MIN_SIZE,
		    SUBJECT_CANVAS_MIN_SIZE, id) {
  browser_node = canvas->browser_diagram();
  itscolor = UmlDefaultColor;
  check_size();
  connect(DrawingSettings::instance(), SIGNAL(changed()), this, SLOT(modified()));
}
Example #12
0
File: voidptr.c Project: Werkov/SIP
/*
 * Implement sequence item sub-script for the type.
 */
static PyObject *sipVoidPtr_item(PyObject *self, SIP_SSIZE_T idx)
{
    if (check_size(self) < 0 || check_index(self, idx) < 0)
        return NULL;

    return SIPBytes_FromStringAndSize(
            (char *)((sipVoidPtrObject *)self)->voidptr + idx, 1);
}
Example #13
0
void SubjectCanvas::modified() {
  // force son reaffichage
  hide();
  check_size();
  show();
  canvas()->update();
  package_modified();
}
Example #14
0
static int test_link2(void)
{
	const char *data = testdata;
	int datalen = testdatalen;
	int err = 0;
	int res;

	start_test("link-unlink-link");
	res = create_file(testfile, data, datalen);
	if (res == -1)
		return -1;

	unlink(testfile2);
	res = link(testfile, testfile2);
	if (res == -1) {
		PERROR("link");
		return -1;
	}
	res = unlink(testfile);
	if (res == -1) {
		PERROR("unlink");
		return -1;
	}
	res = check_nonexist(testfile);
	if (res == -1)
		return -1;
	res = link(testfile2, testfile);
	if (res == -1) {
		PERROR("link");
	}
	res = check_type(testfile, S_IFREG);
	if (res == -1)
		return -1;
	err += check_mode(testfile, 0644);
	err += check_nlink(testfile, 2);
	err += check_size(testfile, datalen);
	err += check_data(testfile, data, 0, datalen);

	res = unlink(testfile2);
	if (res == -1) {
		PERROR("unlink");
		return -1;
	}
	err += check_nlink(testfile, 1);
	res = unlink(testfile);
	if (res == -1) {
		PERROR("unlink");
		return -1;
	}
	res = check_nonexist(testfile);
	if (res == -1)
		return -1;
	if (err)
		return -1;

	success();
	return 0;
}
Example #15
0
void ActivityPartitionCanvas::change_scale() {
  double scale = the_canvas()->zoom();
  
  Q3CanvasRectangle::setVisible(FALSE);
  setSize((int) (width_scale100*scale), (int) (height_scale100*scale));
  check_size();
  recenter();
  Q3CanvasRectangle::setVisible(TRUE);  
}
Example #16
0
int main(int argc, char *argv[])
{
    char out_put[100] = "";
    if(argc != 7)
    {
        strcat(out_put, "error\n");
        printf("%s", out_put);
        return 0;
    }

    else
    {
        int i;
        int j;
        int64_t p[6];
        char* error;
        for(i = 1; i < 7; i = i + 1)
        {
            p[i-1] = strtol(argv[i], &error, 10);
            if (*error != '\0')
            {
                strcat(out_put, "error\n");
                printf("%s", out_put);

                return 0;
            }
        }

        int64_t sides[3];
        sides[0] = length(p[0], p[1], p[2], p[3]);
        sides[1] = length(p[2], p[3], p[4], p[5]);
        sides[2] = length(p[4], p[5], p[0], p[1]);
        if(colin_test(p[0], p[1], p[2], p[3], p[4], p[5]))
        {
            strcat(out_put, "not a triangle");
            printf("%s", out_put);
            return 0;
        }

        for(i = 0; i < 3; i = i + 1)
        {
            if(sides[i] == 0)
            {
                strcat(out_put, "not a triangle");
                printf("%s", out_put);
                return 0;
            }


        }
        strcat(out_put, check_size(sides));
        strcat(out_put, check_angle(sides));
        printf("%s\n", out_put);
        return 0;
    }

}
Example #17
0
bool Buffer::write(const void *data, uint32_t len) {
    if (!check_size(wptr + len)) {
        memcpy(bptr + wptr, data, len);
        wptr += len;
        return true;
    }
    error = true;
    return false;
}
Example #18
0
void check_all(void)
{
  uint8_t size;
  for( size =1; size < 255; size++ )
  {
    printf("size=%d\n", size);
    check_size(size);
  }
}
static noinline int v4l1_compat_get_capabilities(
					struct video_capability *cap,
					struct inode *inode,
					struct file *file,
					v4l2_kioctl drv)
{
	int err;
	struct v4l2_framebuffer fbuf;
	struct v4l2_capability *cap2;

	cap2 = kzalloc(sizeof(*cap2), GFP_KERNEL);
	if (!cap2) {
		err = -ENOMEM;
		return err;
	}
	memset(cap, 0, sizeof(*cap));
	memset(&fbuf, 0, sizeof(fbuf));

	err = drv(inode, file, VIDIOC_QUERYCAP, cap2);
	if (err < 0) {
		dprintk("VIDIOCGCAP / VIDIOC_QUERYCAP: %d\n", err);
		goto done;
	}
	if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY) {
		err = drv(inode, file, VIDIOC_G_FBUF, &fbuf);
		if (err < 0) {
			dprintk("VIDIOCGCAP / VIDIOC_G_FBUF: %d\n", err);
			memset(&fbuf, 0, sizeof(fbuf));
		}
		err = 0;
	}

	memcpy(cap->name, cap2->card,
	       min(sizeof(cap->name), sizeof(cap2->card)));
	cap->name[sizeof(cap->name) - 1] = 0;
	if (cap2->capabilities & V4L2_CAP_VIDEO_CAPTURE)
		cap->type |= VID_TYPE_CAPTURE;
	if (cap2->capabilities & V4L2_CAP_TUNER)
		cap->type |= VID_TYPE_TUNER;
	if (cap2->capabilities & V4L2_CAP_VBI_CAPTURE)
		cap->type |= VID_TYPE_TELETEXT;
	if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY)
		cap->type |= VID_TYPE_OVERLAY;
	if (fbuf.capability & V4L2_FBUF_CAP_LIST_CLIPPING)
		cap->type |= VID_TYPE_CLIPPING;

	cap->channels  = count_inputs(inode, file, drv);
	check_size(inode, file, drv,
		   &cap->maxwidth, &cap->maxheight);
	cap->audios    =  0; /* FIXME */
	cap->minwidth  = 48; /* FIXME */
	cap->minheight = 32; /* FIXME */

done:
	kfree(cap2);
	return err;
}
Example #20
0
double MedianStats::median() {
    check_size(1);
    std::sort(values_.begin(), values_.end());
    size_t n {values_.size()};
    if (n % 2 == 0)
        return (values_[n/2 - 1] + values_[n/2])/2.0;
    else
        return values_[n/2];
}
Example #21
0
std::string unpacker::pop_string() {
  uint32_t length = pop_uint32();
  check_size(length, position_);

  std::string s = std::string(buffer_ + position_, length);
  position_ = static_cast<uint32_t>(position_ + length);

  return s;
}
Example #22
0
/**
 * Validate a given file service s. Events are posted according to 
 * its configuration. In case of a fatal event FALSE is returned.
 */
int check_file(Service_T s) {
  struct stat stat_buf;

  ASSERT(s);

  if (stat(s->path, &stat_buf) != 0) {
    Event_post(s, Event_Nonexist, STATE_FAILED, s->action_NONEXIST, "file doesn't exist");
    return FALSE;
  } else {
    s->inf->st_mode = stat_buf.st_mode;
    if (s->inf->priv.file.st_ino == 0) {
      s->inf->priv.file.st_ino_prev = stat_buf.st_ino;
      s->inf->priv.file.readpos     = stat_buf.st_size;
    } else
      s->inf->priv.file.st_ino_prev = s->inf->priv.file.st_ino;
    s->inf->priv.file.st_ino  = stat_buf.st_ino;
    s->inf->st_uid            = stat_buf.st_uid;
    s->inf->st_gid            = stat_buf.st_gid;
    s->inf->priv.file.st_size = stat_buf.st_size;
    s->inf->timestamp         = MAX(stat_buf.st_mtime, stat_buf.st_ctime);
    DEBUG("'%s' file exists check succeeded\n", s->name);
    Event_post(s, Event_Nonexist, STATE_SUCCEEDED, s->action_NONEXIST, "file exist");
  }

  if (!S_ISREG(s->inf->st_mode)) {
    Event_post(s, Event_Invalid, STATE_FAILED, s->action_INVALID, "is not a regular file");
    return FALSE;
  } else {
    DEBUG("'%s' is a regular file\n", s->name);
    Event_post(s, Event_Invalid, STATE_SUCCEEDED, s->action_INVALID, "is a regular file");
  }

  if (s->checksum)
    check_checksum(s);

  if (s->perm)
    check_perm(s);

  if (s->uid)
    check_uid(s);

  if (s->gid)
    check_gid(s);

  if (s->sizelist)
    check_size(s);

  if (s->timestamplist)
    check_timestamp(s);

  if (s->matchlist)
    check_match(s);

  return TRUE;

}
void Line::set(char* str_new)
{
    int len = strlen(str_new)+1;

    check_size(len + 1);

    memcpy(str, str_new, len + 1);

    recalc_sz();
}
Example #24
0
void sdl_string::set(const char *s, size_t from, size_t len) {
	if (s == 0) {
		return;
	}
	if (len < 0) return;
	check_size(from+len);  // memcpy will overwrite space[from..from+len-1]
	if (len>0)
		::memcpy(&space[from], s, len);
	space[from+len] = 0; // maintain invariant that "invisible" terminator is 0
}
Example #25
0
int update_status(sqlite3 *db, char *newstatus)
{
	int i;
	int return_ret=0;
 	int len_ret;
	int size_ret;
	int update_ret;
	int row_ret;
	
    len_ret=check_list_len(newstatus);
	if(len_ret==-1)
	{
		return_ret=-1;
		goto over;
	}
	if(len_ret==-2)
	{
		return_ret=-2;
		goto over;
	}

	for(i=0;i<MAX_IPC_NUM;i++)
	{
		if(newstatus[i]!='c')
		{
			size_ret=check_size(newstatus[i]);
		    if(size_ret==-1)
		    {
				return_ret=-4;
				goto over;
		    }
			row_ret=check_row(i);
			if(row_ret==-1)
			{
				return_ret=-5;
				goto over;
			}
			if(row_ret==-2)
			{
				return_ret=-3;
				goto over;
			}
			//printf("newstatus[%d]:%c\n",i,newstatus[i]);
			update_ret=update_status_value(i,newstatus[i]);
			if(update_ret==-1)
			{
				return_ret=-6;
				goto over;
			}
		}
	}
	over:
	return return_ret;
	
}
Example #26
0
void ActivityPartitionCanvas::modified() {
  hide();
  hide_lines();
  check_size();
  show();
  update_show_lines();
  check_stereotypeproperties();
  canvas()->update();
  force_sub_inside(FALSE);
  package_modified();
}
Example #27
0
/* Send a NULL terminated string. */
static void send_string(const char *s)
{
   /*while(fieldwidth--) {
      printf_packet.data[printf_packet.size++] = padchar;
      check_size();
   }*/
   while(*s) {
      printf_packet.data[printf_packet.size++] = *s++;
      check_size();
   }
}
Example #28
0
int POOL_MEM::strcpy(const char *str)
{
   int len;

   if (!str) str = "";

   len = strlen(str) + 1;
   check_size(len);
   memcpy(mem, str, len);
   return len - 1;
}
Example #29
0
File: voidptr.c Project: Werkov/SIP
/*
 * The buffer implementation for Python v2.6 and later.
 */
static int sipVoidPtr_getbuffer(PyObject *self, Py_buffer *buf, int flags)
{
    sipVoidPtrObject *v;

    if (check_size(self) < 0)
        return -1;

    v = (sipVoidPtrObject *)self;

    return PyBuffer_FillInfo(buf, self, v->voidptr, v->size, !v->rw, flags);
}
Example #30
0
inline osmium::util::MemoryMapping::MemoryMapping(size_t size, mapping_mode mode, int fd, off_t offset) :
    m_size(check_size(size)),
    m_offset(offset),
    m_fd(resize_fd(fd)),
    m_mapping_mode(mode),
    m_addr(::mmap(nullptr, m_size, get_protection(), get_flags(), m_fd, m_offset)) {
    assert(!(fd == -1 && mode == mapping_mode::readonly));
    if (!is_valid()) {
        throw std::system_error(errno, std::system_category(), "mmap failed");
    }
}