Review Board 1.7.16


Use the correct lower bound for saturated arithmetic

Review Request #2479 - Created April 29, 2013 and submitted

Sean Bright
1.8
Reviewers
asterisk-dev
Asterisk
The current ast_slinear_saturated_* functions use a lower bound of -32767, where they should be using -32768.  I'm only posting the review in case I am missing something obvious.
Compilation and ran a few calls through ConfBridge

Diff revision 1 (Latest)

  1. /branches/1.8/include/asterisk/utils.h: Loading...
/branches/1.8/include/asterisk/utils.h
Revision 386841 New Change
[20] 304 lines
[+20] [+] static force_inline void ast_slinear_saturated_add(short *input, short *value)
305
	int res;
305
	int res;
306

    
   
306

   
307
	res = (int) *input + *value;
307
	res = (int) *input + *value;
308
	if (res > 32767)
308
	if (res > 32767)
309
		*input = 32767;
309
		*input = 32767;
310
	else if (res < -32767)
310
	else if (res < -32768)
311
		*input = -32767;
311
		*input = -32768;
312
	else
312
	else
313
		*input = (short) res;
313
		*input = (short) res;
314
}
314
}
315

    
   
315

   
316
static force_inline void ast_slinear_saturated_subtract(short *input, short *value)
316
static force_inline void ast_slinear_saturated_subtract(short *input, short *value)
317
{
317
{
318
	int res;
318
	int res;
319

    
   
319

   
320
	res = (int) *input - *value;
320
	res = (int) *input - *value;
321
	if (res > 32767)
321
	if (res > 32767)
322
		*input = 32767;
322
		*input = 32767;
323
	else if (res < -32767)
323
	else if (res < -32768)
324
		*input = -32767;
324
		*input = -32768;
325
	else
325
	else
326
		*input = (short) res;
326
		*input = (short) res;
327
}
327
}
328
	
328
	
329
static force_inline void ast_slinear_saturated_multiply(short *input, short *value)
329
static force_inline void ast_slinear_saturated_multiply(short *input, short *value)
330
{
330
{
331
	int res;
331
	int res;
332

    
   
332

   
333
	res = (int) *input * *value;
333
	res = (int) *input * *value;
334
	if (res > 32767)
334
	if (res > 32767)
335
		*input = 32767;
335
		*input = 32767;
336
	else if (res < -32767)
336
	else if (res < -32768)
337
		*input = -32767;
337
		*input = -32768;
338
	else
338
	else
339
		*input = (short) res;
339
		*input = (short) res;
340
}
340
}
341

    
   
341

   
342
static force_inline void ast_slinear_saturated_divide(short *input, short *value)
342
static force_inline void ast_slinear_saturated_divide(short *input, short *value)
[+20] [20] 512 lines
  1. /branches/1.8/include/asterisk/utils.h: Loading...

https://reviewboard.asterisk.org/ runs on a server provided by Digium, Inc. and uses bandwidth donated to the open source Asterisk community by API Digital Communications in Huntsville, AL USA.
Please report problems with this site to asteriskteam@digium.com.