Skip to content

Commit

Permalink
Fixed incorrect a2_Start() error returns
Browse files Browse the repository at this point in the history
a2_Start() would occasionally return a bogus handle 16, which was actually
supposed to be -A2_OVERFLOW, indicated an API message buffer overflow; the
negation was missing. (The return value is A2_handle - not A2_errors.)

Also added dedicated error code A2_MSGOVERFLOW for this situation.

Closes #338.
  • Loading branch information
olofson committed Dec 7, 2017
1 parent fcc4cc0 commit c2c8566
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/a2_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ typedef enum {
A2_DEFERR(LATEMESSAGE, "API message arrived late to engine context")\
A2_DEFERR(MANYARGS, "Too many arguments to VM program")\
\
A2_DEFERR(MSGOVERFLOW, "API message buffer overflow")\
A2_DEFERR(BUFOVERFLOW, "Buffer overflow")\
A2_DEFERR(BUFUNDERFLOW, "Buffer underflow")\
A2_DEFERR(DIVBYZERO, "Division by zero")\
Expand Down
2 changes: 1 addition & 1 deletion src/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ static A2_handle a2_API_Starta(A2_interface *i, A2_handle parent,
return am.b.start.voice;
if((res = a2_writemsgargs(st->fromapi, &am, argc, argv,
offsetof(A2_apimessage, b.start.a))))
return res;
return -res;
return am.b.start.voice;
}

Expand Down
6 changes: 3 additions & 3 deletions src/internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ static inline A2_event **a2_GetEventQueue(A2_state *st, A2_handle handle)
case A2_TVOICE:
return &((A2_voice *)hi->d.data)->events;
default:
return NULL;
return NULL;
}
}

Expand Down Expand Up @@ -1057,7 +1057,7 @@ static inline A2_errors a2_writemsg(SFIFO *f, A2_apimessage *m, unsigned size)
"%d bytes (min: %d)", size, A2_APIREADSIZE);
#endif
if(sfifo_Space(f) < size)
return A2_OVERFLOW;
return A2_MSGOVERFLOW;
m->size = size;
m->b.common.argc = 0;
if(sfifo_Write(f, m, size) != size)
Expand All @@ -1079,7 +1079,7 @@ static inline A2_errors a2_writemsgargs(SFIFO *f, A2_apimessage *m,
if(argc > A2_MAXARGS)
return A2_MANYARGS;
if(sfifo_Space(f) < size)
return A2_OVERFLOW;
return A2_MSGOVERFLOW;
m->size = size;
m->b.common.argc = argc;
memcpy((char *)m + argoffs, argv, argsize);
Expand Down

0 comments on commit c2c8566

Please sign in to comment.