Exemplo n.º 1
0
void
array_test (void)
{
  int n = 1;
  array_t *a = array_from_str ("0x1xx0x1");
  array_t *b = array_from_str ("01xx10x1");
  array_isect (a, b, n, a);
  char *s = array_to_str (a, n, false);
  print_safe (s);
  free (s);
  free (a);
  free (b);

  a = array_from_str ("01xx0011,xxxx1011");
  s = array_to_str (a, 2, false);
  print_safe (s);
  free (s);
  free (a);

  a = array_from_str ("11000001,10001000,00011111,001101xx");
  s = array_to_str (a, 4, true);
  print_safe (s);
  free (s);
  free (a);
}
Exemplo n.º 2
0
static void print_human_data(struct print_cursor *curs,
    const struct usbmon_packet_1 *ep, const unsigned char *data, int data_len)
{
	int any_printable;
	int i;

	print_safe(curs, "   ");
	for (i = 0; i < data_len; i++) {
		if (i % 4 == 0)
			print_safe(curs, " ");
		print_safe(curs, "%02x", data[i]);
	}
	print_safe(curs, "\n");

	any_printable = 0;
	for (i = 0; i < data_len; i++) {
		if (isprint(data[i])) {
			any_printable = 1;
			break;
		}
	}
	if (any_printable) {
		print_safe(curs, "   ");
		for (i = 0; i < data_len; i++) {
			if (i % 4 == 0)
				print_safe(curs, " ");
			print_safe(curs, " %c",
			    isprint(data[i]) ? data[i] : '.');
		}
		print_safe(curs, "\n");
	}
}
Exemplo n.º 3
0
void * work1 (void *arg)
{
  int r;
  klee_make_symbolic(&r, sizeof(r), "r");
  
  printf("r is now symbolic\n");
  
  
  if(r)
    {
      pthread_mutex_lock (&cs0);
      globalX++;
      pthread_mutex_lock (&cs1);
      print_safe();
      globalY++;
    }
  else
    {
      pthread_mutex_lock (&cs1);
      printf("work1: got lock 1\n");
      print_deadlock();
      globalX++;
      pthread_mutex_lock (&cs0);
      printf("work1: got lock 0\n");

      globalY++;
    }


  if(r)
    {
      pthread_mutex_unlock (&cs1);
      print_safe();
      pthread_mutex_unlock (&cs0);
    }
  else
    {
      pthread_mutex_unlock (&cs0);
      printf("work1: released lock 0\n");
      print_deadlock();
      pthread_mutex_unlock (&cs1);
      printf("work1: released lock 1\n");
    }
  return 0;
}
Exemplo n.º 4
0
Arquivo: gpg.c Projeto: zixia/wmail
static int select_key(const char *fingerprint, const char *shortname,
		      const char *key,
		      struct gpg_list_info *gli,
		      int is_select)
{
	printf("<OPTION VALUE=\"");
	print_attrencodedlen(fingerprint, strlen(fingerprint), 0, stdout);
	printf("\"%s>", is_select ? " SELECTED":"");

	print_safe(shortname);
	return (0);
}
Exemplo n.º 5
0
static int select_key(const char *fingerprint, const char *shortname,
		      const char *key,
		      struct gpg_list_info *gli,
		      int is_select)
{
	printf("<option value=\"");
	print_attrencodedlen(fingerprint, strlen(fingerprint), 0, stdout);
	printf("\"%s>", is_select ? " selected='selected'":"");

	print_safe(shortname);
	printf("</option>");
	return (0);
}
Exemplo n.º 6
0
static int show_key(const char *fingerprint, const char *shortname,
                    const char *key, int invalid,
		    struct gpg_list_info *gli)
{
	struct listinfo *li=(struct listinfo *)gli->voidarg;

	printf("<tr valign=\"middle\" class=\"%s\"><td>"
	       "<input type=\"radio\" name=\"%s\" value=\"",
	       li->issecret ? "gpgseckey":"gpgpubkey",
	       li->issecret ? "seckeyname":"pubkeyname");

	print_attrencodedlen(fingerprint, strlen(fingerprint), 0, stdout);
	printf("\"%s /></td><td><span class=\"tt\">",
	       li->default_key && strcmp(li->default_key, fingerprint) == 0
	       ? " checked=\"checked\"":"");
	print_safe(key);
	printf("</span></td></tr>\n");
	return (0);
}
Exemplo n.º 7
0
Arquivo: gpg.c Projeto: zixia/wmail
static int show_key(const char *fingerprint, const char *shortname,
                    const char *key, int invalid,
		    struct gpg_list_info *gli)
{
	struct listinfo *li=(struct listinfo *)gli->voidarg;

	printf("<TR VALIGN=MIDDLE CLASS=\"%s\"><TD>"
	       "<input type=radio name=%s value=\"",
	       li->issecret ? "gpgseckey":"gpgpubkey",
	       li->issecret ? "seckeyname":"pubkeyname");

	print_attrencodedlen(fingerprint, strlen(fingerprint), 0, stdout);
	printf("\"%s></TD><TD><TT>",
	       li->default_key && strcmp(li->default_key, fingerprint) == 0
	       ? " CHECKED":"");
	print_safe(key);
	printf("</TT></TD></TR>\n");
	return (0);
}
Exemplo n.º 8
0
void print_human(const struct params *prm, const struct usbmon_packet_1 *ep,
    const unsigned char *data, uint64_t start_sec)
{
	struct print_cursor pcur;
	char udir, utype;
	int data_len, i;
	int ndesc;				/* Display this many */
	const struct usbmon_isodesc *dp;
	int cnt;
	ssize_t rc;

	print_start(&pcur, prm->print_buf, prm->print_size);

	if ((data_len = ep->len_cap) < 0) {	/* Overflow */
		data_len = 0;
	}

#if 0
	enum { TAG_BUF_SIZE = 17 };
	char tag_buf[TAG_BUF_SIZE];
	print_human_tag(tag_buf, TAG_BUF_SIZE, prm->tagp, ep);
#endif
	/*
	 * We cast into a truncated type for readability.
	 * The danger of collisions is negligible.
	 */
	print_safe(&pcur, "%08x", (unsigned int) ep->id);

	udir = ((ep->epnum & 0x80) != 0) ? 'i' : 'o';
	switch (ep->xfer_type & 0x3) {
	case PIPE_ISOCHRONOUS:	utype = 'Z'; break;
	case PIPE_INTERRUPT:	utype = 'I'; break;
	case PIPE_CONTROL:	utype = 'C'; break;
	default: /* PIPE_BULK */  utype = 'B';
	}
	print_safe(&pcur,
	    " %u.%06u %c %c%c:%u:%03u:%u",
	    (unsigned int)(ep->ts_sec - start_sec), ep->ts_usec,
	    ep->type,
	    utype, udir, ep->busnum, ep->devnum, ep->epnum & 0x7f);

	if (ep->type == 'E') {
		print_safe(&pcur, " %d", ep->status);
	} else {
		if (ep->flag_setup == 0) {
			/* Setup packet is present and captured */
			print_safe(&pcur,
			    " s %02x %02x %04x %04x %04x",
			    ep->s.setup[0],
			    ep->s.setup[1],
			    (ep->s.setup[3] << 8) | ep->s.setup[2],
			    (ep->s.setup[5] << 8) | ep->s.setup[4],
			    (ep->s.setup[7] << 8) | ep->s.setup[6]);
		} else if (ep->flag_setup != '-') {
			/* Unable to capture setup packet */
			print_safe(&pcur,
			    " %c __ __ ____ ____ ____", ep->flag_setup);
		} else {
			/* No setup for this kind of URB */
			if (ep->type == 'S' && ep->status == -EINPROGRESS) {
				print_safe(&pcur, " -");
			} else {
				print_safe(&pcur, " %d", ep->status);
			}
			if (usb_typeisoc(ep->xfer_type) ||
			    usb_typeint(ep->xfer_type)) {
				print_safe(&pcur, ":%d", ep->interval);
			}
			if (usb_typeisoc(ep->xfer_type)) {
				print_safe(&pcur, ":%d", ep->start_frame);
				if (ep->type == 'C') {
					print_safe(&pcur,
					    ":%d", ep->s.iso.error_count);
				}
			}
		}
		if (usb_typeisoc(ep->xfer_type)) {
			/*
			 * This is the number of descriptors used by HC.
			 */
			print_safe(&pcur, " %d", ep->s.iso.numdesc);

			/*
			 * This is the number of descriptors which we print.
			 */
			ndesc = ep->ndesc;
			if (ndesc > ISODESC_MAX)
				ndesc = ISODESC_MAX;
			if (ndesc * sizeof(struct usbmon_isodesc) > data_len) {
				ndesc = data_len / sizeof(struct usbmon_isodesc);
			}
			/* This is aligned by malloc */
			dp = (struct usbmon_isodesc *) data;
			for (i = 0; i < ndesc; i++) {
				print_safe(&pcur,
				    " %d:%u:%u",
				    dp->iso_stat, dp->iso_off, dp->iso_len);
				dp++;
			}

			/*
			 * The number of descriptors captured is used to
			 * find where the data starts.
			 */
			ndesc = ep->ndesc;
			if (ndesc * sizeof(struct usbmon_isodesc) > data_len) {
				data_len = 0;
			} else {
				data += ndesc * sizeof(struct usbmon_isodesc);
				data_len -= ndesc * sizeof(struct usbmon_isodesc);
			}
		}
	}

	print_safe(&pcur, " %d", ep->length);

	if (ep->length > 0) {
		if (ep->flag_data == 0) {
			print_safe(&pcur, " =\n");
			if (data_len >= prm->data_max)
				data_len = prm->data_max;
			print_human_data(&pcur, ep, data, data_len);
		} else {
			print_safe(&pcur, " %c\n", ep->flag_data);
		}
	} else {
		print_safe(&pcur, "\n");
	}

	cnt = print_done(&pcur);
	if ((rc = write(1, prm->print_buf, cnt)) < cnt) {
		if (rc < 0) {
			fprintf(stderr, TAG ": Write error: %s\n",
			    strerror(errno));
		} else {
			fprintf(stderr, TAG ": Short write\n");
		}
		exit(1);
	}
}
Exemplo n.º 9
0
void print_48(const struct params *prm, const struct usbmon_packet *ep,
    const unsigned char *data)
{
	struct print_cursor pcur;
	char udir, utype;
	int data_len, i;
	int cnt;
	ssize_t rc;

	print_start(&pcur, prm->print_buf, prm->print_size);

	udir = ((ep->epnum & 0x80) != 0) ? 'i' : 'o';
	switch (ep->xfer_type & 0x3) {
	case PIPE_ISOCHRONOUS:	utype = 'Z'; break;
	case PIPE_INTERRUPT:	utype = 'I'; break;
	case PIPE_CONTROL:	utype = 'C'; break;
	default: /* PIPE_BULK */  utype = 'B';
	}
	print_safe(&pcur,
	    "%llx %u %c %c%c:%03u:%02u",
	    (long long) ep->id,
	    (unsigned int)(ep->ts_sec & 0xFFF) * 1000000 + ep->ts_usec,
	    ep->type,
	    utype, udir, ep->devnum, ep->epnum & 0x7f);

	if (ep->flag_setup == 0) {   /* Setup packet is present and captured */
		print_safe(&pcur,
		    " s %02x %02x %04x %04x %04x",
		    ep->setup[0],
		    ep->setup[1],
		    (ep->setup[3] << 8) | ep->setup[2],
		    (ep->setup[5] << 8) | ep->setup[4],
		    (ep->setup[7] << 8) | ep->setup[6]);
	} else if (ep->flag_setup != '-') { /* Unable to capture setup packet */
		print_safe(&pcur,
		    " %c __ __ ____ ____ ____", ep->flag_setup);
	} else {                     /* No setup for this kind of URB */
		print_safe(&pcur, " %d", ep->status);
	}
	print_safe(&pcur, " %d", ep->length);

	if (ep->length > 0) {
		if (ep->flag_data == 0) {
			print_safe(&pcur, " =");
			if ((data_len = ep->len_cap) >= DATA_MAX)
				data_len = DATA_MAX;
			for (i = 0; i < data_len; i++) {
				if (i % 4 == 0) {
					print_safe(&pcur, " ");
				}
				print_safe(&pcur, "%02x", data[i]);
			}
			print_safe(&pcur, "\n");
		} else {
			print_safe(&pcur, " %c\n", ep->flag_data);
		}
	} else {
		print_safe(&pcur, "\n");
	}

	cnt = print_done(&pcur);
	if ((rc = write(1, prm->print_buf, cnt)) < cnt) {
		if (rc < 0) {
			fprintf(stderr, TAG ": Write error: %s\n",
			    strerror(errno));
		} else {
			fprintf(stderr, TAG ": Short write\n");
		}
		exit(1);
	}
}