summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <PromyLOPh@gmail.com>2008-08-25 11:37:34 +0200
committerLars-Dominik Braun <PromyLOPh@gmail.com>2008-08-25 11:37:34 +0200
commitd79795d1576d69a57a852c4f279da133e68755df (patch)
treed941ad24b588a5830bfbafa9dcbd24b278379825
parent496e61c506f283135a52a95dec5bf43c87e39cc8 (diff)
downloadpianobar-windows-d79795d1576d69a57a852c4f279da133e68755df.tar.gz
pianobar-windows-d79795d1576d69a57a852c4f279da133e68755df.tar.bz2
pianobar-windows-d79795d1576d69a57a852c4f279da133e68755df.zip
piano: Code refactoring
Avoid strncat/strncpy, cache strlen result, ...
-rw-r--r--libpiano/src/http.c6
-rw-r--r--libpiano/src/xml.c13
2 files changed, 9 insertions, 10 deletions
diff --git a/libpiano/src/http.c b/libpiano/src/http.c
index 88d299c..96655ca 100644
--- a/libpiano/src/http.c
+++ b/libpiano/src/http.c
@@ -28,7 +28,6 @@ THE SOFTWARE.
#define PIANO_HTTP_BUFFER_SIZE 100000
-/* FIXME: curl has a receive limit, use it! */
/* callback for curl, writes data to buffer
* @param received data
* @param block size
@@ -37,15 +36,14 @@ THE SOFTWARE.
* @return written bytes
*/
size_t PianoCurlRetToVar (void *ptr, size_t size, size_t nmemb, void *stream) {
- char *charPtr = ptr;
char *streamPtr = stream;
size_t streamPtrN = strlen (streamPtr);
- if (streamPtrN + nmemb > PIANO_HTTP_BUFFER_SIZE) {
+ if ((streamPtrN + nmemb) > (PIANO_HTTP_BUFFER_SIZE - 1)) {
printf ("buffer overflow...\n");
return 0;
} else {
- memcpy (streamPtr+streamPtrN, charPtr, size*nmemb);
+ memcpy (&streamPtr[streamPtrN], ptr, size*nmemb);
return size*nmemb;
}
}
diff --git a/libpiano/src/xml.c b/libpiano/src/xml.c
index f43d4a8..73f9030 100644
--- a/libpiano/src/xml.c
+++ b/libpiano/src/xml.c
@@ -238,15 +238,16 @@ void PianoXmlParsePlaylistCb (const char *key, const xmlNode *value,
/* last 48 chars of audioUrl are encrypted, but they put the key
* into the door's lock; dumb pandora... */
const char urlTailN = 48;
- char *urlTail, *urlTailCrypted = valueStr + (strlen (valueStr) - urlTailN);
+ const size_t valueStrN = strlen (valueStr);
+ char *urlTail = NULL,
+ *urlTailCrypted = &valueStr[valueStrN - urlTailN];
urlTail = PianoDecryptString (urlTailCrypted);
- song->audioUrl = calloc (strlen (valueStr) + 1, sizeof (char));
- strncpy (song->audioUrl, valueStr, strlen (valueStr) - urlTailN);
+ song->audioUrl = calloc (valueStrN + 1, sizeof (*song->audioUrl));
+ memcpy (song->audioUrl, valueStr, valueStrN - urlTailN);
/* FIXME: the key seems to be broken... so ignore 8 x 0x08 postfix;
* urlTailN/2 because the encrypted hex string is now decoded */
- strncat (song->audioUrl, urlTail, (urlTailN/2)-8);
- PianoFree (urlTail, 0);
-
+ memcpy (&song->audioUrl[valueStrN - urlTailN], urlTail, urlTailN/2 - 8);
+ PianoFree (urlTail, urlTailN/2);
} else if (strcmp ("artistSummary", key) == 0) {
song->artist = strdup (valueStr);
} else if (strcmp ("musicId", key) == 0) {