Skip to content

Commit

Permalink
took out the get_len_and_ptr macros from o.printbytes and o.validate …
Browse files Browse the repository at this point in the history
…so they actually process malformed packets
  • Loading branch information
maccallum committed Jan 31, 2019
1 parent 5e10c60 commit 1e501ad
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
21 changes: 20 additions & 1 deletion src/o.printbytes/o.printbytes.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,26 @@ void *opbytes_new(t_symbol *msg, short argc, t_atom *argv);
//void opbytes_fullPacket(t_opbytes *x, long len, long ptr)
void opbytes_fullPacket(t_opbytes *x, t_symbol *msg, int argc, t_atom *argv)
{
OMAX_UTIL_GET_LEN_AND_PTR
//OMAX_UTIL_GET_LEN_AND_PTR
{
// get len and ptr. can't use macro because it validates the contents and
// bails if anything's wrong, but we want to process a bad packet in this obj
if(argc != 2){
object_error((t_object *)x, "expected 2 arguments but got %d", argc);
return;
}
if(atom_gettype(argv) != A_LONG){
object_error((t_object *)x, "argument 1 should be an int");
return;
}
if(atom_gettype(argv + 1) != A_LONG){
object_error((t_object *)x, "argument 2 should be an int");
return;
}
}
long len = atom_getlong(argv);
char *ptr = (char *)atom_getlong(argv + 1);

unsigned char *buf = (unsigned char *)ptr;
int i;
post("%-12s%-12s%-12s%s", "Byte #", "ASCII", "Decimal", "Hex\n");
Expand Down
21 changes: 20 additions & 1 deletion src/o.validate/o.validate.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void *ovalidate_class;

void ovalidate_fullPacket(t_ovalidate *x, t_symbol *msg, int argc, t_atom *argv)
{
OMAX_UTIL_GET_LEN_AND_PTR;
//OMAX_UTIL_GET_LEN_AND_PTR;
/*
t_osc_err e = osc_error_bundleSanityCheck(len, ptr);
if(e){
Expand All @@ -83,6 +83,25 @@ void ovalidate_fullPacket(t_ovalidate *x, t_symbol *msg, int argc, t_atom *argv)
return;
}
*/
{
// get len and ptr. can't use macro because it validates the contents and
// bails if anything's wrong, but we want to process a bad packet in this obj
if(argc != 2){
object_error((t_object *)x, "expected 2 arguments but got %d", argc);
return;
}
if(atom_gettype(argv) != A_LONG){
object_error((t_object *)x, "argument 1 should be an int");
return;
}
if(atom_gettype(argv + 1) != A_LONG){
object_error((t_object *)x, "argument 2 should be an int");
return;
}
}
long len = atom_getlong(argv);
char *ptr = (char *)atom_getlong(argv + 1);

if(*ptr != '#' && *ptr != '/'){
char errstr[128];
snprintf(errstr, 128, "invalid packet: packet does not begin with a # or a /");
Expand Down

0 comments on commit 1e501ad

Please sign in to comment.