Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Sort out some off-by-one errors

  • Loading branch information...
commit 324bb1d7d25a7e58866e6c576fc4a323b348fbde 1 parent f47b369
@olabini authored
Showing with 6 additions and 4 deletions.
  1. +6 −4 ext/ruby/src/java/org/yecht/ruby/YechtYAML.java
View
10 ext/ruby/src/java/org/yecht/ruby/YechtYAML.java
@@ -153,7 +153,7 @@ public int read(Pointer buf, JechtIO.Str str, int max_size, int skip) {
private static int extractInt(byte[] buff, int p, int pend) {
int len = 0;
- while(Character.isDigit((char)buff[p+len]) && (p+len) < pend) {
+ while((p+len) < pend && Character.isDigit((char)buff[p+len])) {
len++;
}
try {
@@ -163,6 +163,7 @@ private static int extractInt(byte[] buff, int p, int pend) {
// rb_syck_mktime
public static IRubyObject makeTime(Ruby runtime, Pointer str, int len) {
+// System.err.println("makeTime(" + new String(str.buffer, str.start, len) + ")");
int ptr = str.start;
int pend = ptr + len;
IRubyObject year = runtime.newFixnum(0);
@@ -215,7 +216,7 @@ public static IRubyObject makeTime(Ruby runtime, Pointer str, int len) {
System.arraycopy(str.buffer, ptr+1, padded, 0, end - (ptr+1));
try {
usec = Long.parseLong(new String(padded, 0, 6, "ISO-8859-1"));
- } catch(Exception e) {}
+ } catch(java.io.UnsupportedEncodingException e) {}
} else {
usec = 0;
}
@@ -247,15 +248,16 @@ public static IRubyObject makeTime(Ruby runtime, Pointer str, int len) {
tz_offset += extractInt(str.buffer, ptr, pend) * 60;
}
}
-
+
IRubyObject time = runtime.getClass("Time").callMethod(runtime.getCurrentContext(), "utc", new IRubyObject[]{year,mon,day,hour,min,sec});
long tmp = RubyNumeric.num2long(time.callMethod(runtime.getCurrentContext(), "to_i")) - tz_offset;
return runtime.getClass("Time").callMethod(runtime.getCurrentContext(), "at", new IRubyObject[]{runtime.newFixnum(tmp), runtime.newFixnum(usec)});
- } catch(Exception e) {}
+ } catch(java.io.UnsupportedEncodingException e) {}
} else {
// Make UTC time
return runtime.getClass("Time").callMethod(runtime.getCurrentContext(), "utc", new IRubyObject[]{year,mon,day,hour,min,sec,runtime.newFixnum(usec)});
}
+ System.err.println("oopsie, returning null");
return null;
}
Please sign in to comment.
Something went wrong with that request. Please try again.