Hi, i detected a few division by zeros in file:linux-2.6.29.3/sound/soc/codecs/tlv320aic23.c This is deteted with the static code analyis tool cppcheck. Cppcheck prints the following output: [linux-2.6.29.3/sound/soc/codecs/tlv320aic23.c:296]: (error) Division by zero [linux-2.6.29.3/sound/soc/codecs/tlv320aic23.c:297]: (error) Division by zero [linux-2.6.29.3/sound/soc/codecs/tlv320aic23.c:300]: (error) Division by zero [linux-2.6.29.3/sound/soc/codecs/tlv320aic23.c:301]: (error) Division by zero Take a loop at the code tlv320aic23.c at line 296: #define SR_MULT (11*12) #define A(x) (x) ? (SR_MULT/x) : 0 static const unsigned char sr_adc_mult_table[] = { A(2), A(2), A(12), A(12), A(0), A(0), A(3), A(1), A(2), A(2), A(11), A(11), A(0), A(0), A(0), A(1) }; indeed, there is a division by zero! At the lines 297, 300 and 301 happens the same! Best regards Ettl Martin
Reassigned to ALSA.
Which compiler are you using? As you see in the definition A(), it does zero-check before doing the division. So, if the compiler does the right job, zero division must not happen. Thus I suspect it's a compiler-dependent issue. As a workaround, just replace A(0) with 0.
i created the following testcase: #define SR_MULT (11*12) #define A(x) (x) ? (SR_MULT/x) : 0 static const unsigned char sr_adc_mult_table[] = { A(2), A(2), A(12), A(12), A(0), A(0), A(3), A(1), A(2), A(2), A(11), A(11), A(0), A(0), A(0), A(1) }; int main() {} My compiler says: $ g++ -o test test.cpp test.cpp:4: warning: division by zero test.cpp:4: warning: division by zero test.cpp:5: warning: division by zero test.cpp:5: warning: division by zero test.cpp:5: warning: division by zero I am using g++-4.3.3 on ubuntu linux g++ -v Using built-in specs. Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.3.3-5ubuntu4' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4) Regards Martin
By the way, at linux-2.6.29.3/sound/soc/codecs/tlv320aic23.c happens the same! [linux-2.6.29.3/sound/soc/codecs/tlv320aic23.c:296]: (error) Division by zero [linux-2.6.29.3/sound/soc/codecs/tlv320aic23.c:297]: (error) Division by zero [linux-2.6.29.3/sound/soc/codecs/tlv320aic23.c:300]: (error) Division by zero [linux-2.6.29.3/sound/soc/codecs/tlv320aic23.c:301]: (error) Division by zero
Do you get the same error with gcc, not g++? It shouldn't give any errors. It seems like a C++ specific issue.
Indeed, its a g++ specific problem. I tested also g++-3.3, it prints the following message: $g++-3.3 -o test test.c test.c:4: warning: division by zero in `132 / 0' test.c:4: warning: division by zero in `132 / 0' test.c:5: warning: division by zero in `132 / 0' test.c:5: warning: division by zero in `132 / 0' test.c:5: warning: division by zero in `132 / 0' gcc compiles without errors or warnings. Thats strange.