summaryrefslogtreecommitdiffstats
path: root/libk8055
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2011-06-05 22:43:10 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2011-06-05 22:43:10 +0200
commit61c694ac08f1b6b3e80f273b30bec05afbb5c824 (patch)
tree147c21b719f058c70f8a969e0f7104eeda891a07 /libk8055
parent29c26448113c49a2133ff1410f242bf1aeb6e1dc (diff)
downloadk8055-61c694ac08f1b6b3e80f273b30bec05afbb5c824.zip
k8055-61c694ac08f1b6b3e80f273b30bec05afbb5c824.tar.gz
check value pointers before assignments
Diffstat (limited to 'libk8055')
-rw-r--r--libk8055/libk8055.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/libk8055/libk8055.c b/libk8055/libk8055.c
index 917cff0..09691b1 100644
--- a/libk8055/libk8055.c
+++ b/libk8055/libk8055.c
@@ -325,8 +325,8 @@ int k8055_read_analog_channel( struct k8055_dev* dev, int channel ) {
int k8055_read_all_analog( struct k8055_dev* dev, int* data1, int* data2 ) {
if ( k8055_read( dev )!=0 ) return K8055_ERROR;
- *data1 = dev->data_in[ANALOG_1_OFFSET];
- *data2 = dev->data_in[ANALOG_2_OFFSET];
+ if(data1) *data1 = dev->data_in[ANALOG_1_OFFSET];
+ if(data2) *data2 = dev->data_in[ANALOG_2_OFFSET];
return 0;
}
@@ -421,14 +421,14 @@ int k8055_read_all_digital( struct k8055_dev* dev ) {
int k8055_read_all_values( struct k8055_dev* dev, int* data1, int* data2, int* data3, int* data4, int* data5 ) {
if ( k8055_read( dev )!=0 ) return K8055_ERROR;
- *data1 = (
+ if(data1) *data1 = (
( ( dev->data_in[DIGITAL_INP_OFFSET] >> 4 ) & 0x03 ) | /* Input 1 and 2 */
( ( dev->data_in[DIGITAL_INP_OFFSET] << 2 ) & 0x04 ) | /* Input 3 */
( ( dev->data_in[DIGITAL_INP_OFFSET] >> 3 ) & 0x18 ) ); /* Input 4 and 5 */
- *data2 = dev->data_in[ANALOG_1_OFFSET];
- *data3 = dev->data_in[ANALOG_2_OFFSET];
- *data4 = *( ( short int* )( &dev->data_in[COUNTER_1_OFFSET] ) );
- *data5 = *( ( short int* )( &dev->data_in[COUNTER_2_OFFSET] ) );
+ if(data2) *data2 = dev->data_in[ANALOG_1_OFFSET];
+ if(data3) *data3 = dev->data_in[ANALOG_2_OFFSET];
+ if(data4) *data4 = *( ( short int* )( &dev->data_in[COUNTER_1_OFFSET] ) );
+ if(data5) *data5 = *( ( short int* )( &dev->data_in[COUNTER_2_OFFSET] ) );
return 0;
}
@@ -567,11 +567,11 @@ long ReadAllDigital() {
int ReadAllValues( long int* data1, long int* data2, long int* data3, long int* data4, long int* data5 ) {
int d1, d2, d3, d4, d5;
int r = k8055_read_all_values( curr_dev, &d1, &d2, &d3, &d4, &d5 );
- *data1 = d1;
- *data2 = d2;
- *data3 = d3;
- *data4 = d4;
- *data5 = d5;
+ if(data1) *data1 = d1;
+ if(data2) *data2 = d2;
+ if(data3) *data3 = d3;
+ if(data4) *data4 = d4;
+ if(data5) *data5 = d5;
return r;
}
int SetAllValues( int DigitalData, int AdData1, int AdData2 ) {