Permalink
Browse files

error check bundle timestamp and items. Sending a bogus timestamp can…

… crash scserver.
  • Loading branch information...
1 parent 6a88aa0 commit 57346d0258b9193b0ce3f42af1816bc7a9c2f8f8 @samaaron samaaron committed Sep 8, 2011
Showing with 10 additions and 2 deletions.
  1. +4 −1 src/overtone/osc/encode.clj
  2. +6 −1 src/overtone/osc/util.clj
@@ -24,9 +24,12 @@
(osc-pad buf))
(defn encode-timetag
- "Encode timetag into buf. Timestamp defaults now if not specifically passed."
+ "Encode timetag into buf. Timestamp defaults to (now) if not specifically
+ passed. Throws exception if timestamp isn't a number."
([buf] (encode-timetag buf OSC-TIMETAG-NOW))
([buf timestamp]
+ (when-not (number? timestamp)
+ (throw (IllegalArgumentException. (str "OSC bundle timestamp needs to be a number. Got: " (type timestamp) " - " timestamp))))
(if (= timestamp OSC-TIMETAG-NOW)
(doto buf (.putInt 0) (.putInt 1))
(let [ntp-timestamp (TimeStamp/getNtpTime (long timestamp))
@@ -86,8 +86,13 @@
(rest (str/split path #"/")))
(defn mk-osc-bundle
- "Create an osc bundle"
+ "Create an osc bundle. Throws exceptions if the timestamp and items aren't the
+ correct types (number and list respectively)."
[timestamp items]
+ (when-not (number? timestamp)
+ (throw (IllegalArgumentException. (str "OSC bundle timestamp param needs to be a number. Got: " (type timestamp) " - " timestamp))))
+ (when-not (sequential? items)
+ (throw (IllegalArgumentException. (str "OSC bundle items param needs to be a list. Got: " (type items) " - " items))))
(with-meta {:timestamp timestamp
:items items}
{:type :osc-bundle}))

0 comments on commit 57346d0

Please sign in to comment.