adafruit/adafruit-beaglebone-io-python — pull request #29 by bit-hacker (2013-08-16 16:57:05+00:00)
Title: Update c_pwm.c

Justin,

In definition of struct pwm_exp, extended length of key by 1 to ensure room for a terminating byte. Currently, the code doesn't check this, expecting strncpy in pwm_start to trim and NUL-terminate the string.

In lookup_exported_pwm, return "not-found" condition as NULL, not 0, per general pointer usage recommendations.

In pwm_start, added code to ensure NUL-termination of the key.

In pwm_disable, there's a path that doesn't set prev_pwm and can leave it NULL. It being NULL seems to indicate a "first-time" flag, for when the first item in the list is matched. If the search should be terminated after finding device "key", should break be used? Reasonably, a device named "key" should only be found once in the tree, but as coded, it seems that this search loop might find it more than once.

In pwm_set_polarity, the original length of the buffer as 5 will cover positive 16-bit integers, but not room for a trailing NUL byte. If accidently negative, a size of 7 will include room for the sign without breaking.

At UCSD, we are intending to use this as a base for an instruction class.

Bob Seegmiller