From d85073dc1f6c25d09610b8c56871474eaeae55d4 Mon Sep 17 00:00:00 2001
From: "Kevin P. Fleming" <kpfleming@digium.com>
Date: Tue, 18 Apr 2006 21:39:20 +0000
Subject: [PATCH] correct array index calculation (thanks mtaht3!) update
 header file comments to reflect new usage of structure field

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@21207 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 include/asterisk/translate.h | 6 ++++--
 translate.c                  | 5 +++++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/include/asterisk/translate.h b/include/asterisk/translate.h
index 21643fe328..6d5ed15262 100644
--- a/include/asterisk/translate.h
+++ b/include/asterisk/translate.h
@@ -65,8 +65,10 @@ struct ast_trans_pvt;	/* declared below */
  */
 struct ast_translator {
 	const char name[80];		/*! Name of translator */
-	int srcfmt;			/*! Source format (note: bit position) */
-	int dstfmt;			/*! Destination format (note: bit position) */
+	int srcfmt;			/*! Source format (note: bit position,
+					  converted to index during registration) */
+	int dstfmt;			/*! Destination format (note: bit position,
+					  converted to index during registration) */
 
 	/*! initialize private data associated with the translator */
 	void *(*newpvt)(struct ast_trans_pvt *);
diff --git a/translate.c b/translate.c
index 0edfa54ca5..d713817539 100644
--- a/translate.c
+++ b/translate.c
@@ -400,6 +400,7 @@ static void rebuild_matrix(int samples)
 		ast_log(LOG_DEBUG, "Resetting translation matrix\n");
 
 	bzero(tr_matrix, sizeof(tr_matrix));
+
 	/* first, compute all direct costs */
 	AST_LIST_TRAVERSE(&translators, t, list) {
 		x = t->srcfmt;
@@ -413,6 +414,7 @@ static void rebuild_matrix(int samples)
 			tr_matrix[x][z].cost = t->cost;
 		}
 	}
+
 	/*
 	 * For each triple x, y, z of distinct formats, check if there is
 	 * a path from x to z through y which is cheaper than what is
@@ -656,6 +658,9 @@ int ast_translator_best_choice(int *dst, int *srcs)
 
 unsigned int ast_translate_path_steps(unsigned int dest, unsigned int src)
 {
+	/* convert bitwise format numbers into array indices */
+	src = powerof(src);
+	dest = powerof(dest);
 	if (!tr_matrix[src][dest].step)
 		return -1;
 	else
-- 
GitLab