File: decimal-fetch-between-minus-one-and-zero.patch

package info (click to toggle)
libdbd-firebird-perl 1.24-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 728 kB
  • sloc: perl: 4,419; ansic: 2,367; makefile: 12
file content (37 lines) | stat: -rw-r--r-- 1,650 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
b4fad5d264abafeb26e1333b74f6a5c2f75f4869 dbd_st_fetch: fix conversion of numerics between -1 and 0
diff --git a/dbdimp.c b/dbdimp.c
index 1c48d7c..ff7b510 100644
--- a/dbdimp.c
+++ b/dbdimp.c
@@ -1431,20 +1431,28 @@ AV *dbd_st_fetch(SV *sth, imp_sth_t *imp_sth)
 #endif
                     if (var->sqlscale == 0) {
                         snprintf(buf, sizeof(buf), "%"DBD_IB_INT64f, i);
+                        sv_setpvn(sv, buf, strlen(buf));
                     } else {
+                        bool sign = ( i < 0 );
                         ISC_INT64 divisor, remainder;
                         divisor   = scales[-var->sqlscale];
+                        if (sign) divisor = -divisor;
                         remainder = (i%divisor);
                         if (remainder < 0) remainder = -remainder;
 
-                        snprintf(buf, sizeof(buf),
+                        snprintf(buf+1, sizeof(buf)-1,
                                 "%"DBD_IB_INT64f".%0*"DBD_IB_INT64f,
                                 i/divisor, -var->sqlscale, remainder);
 			DBI_TRACE_imp_xxh(imp_sth, 3, (DBIc_LOGPIO(imp_sth), "-------------->SQLINT64=%"DBD_IB_INT64f".%0*"DBD_IB_INT64f,i/divisor, -var->sqlscale, remainder ));
 
+                        if (sign) {
+                            *buf = '-';
+                            sv_setpvn(sv, buf, strlen(buf));
+                        }
+                        else {
+                            sv_setpvn(sv, buf+1, strlen(buf+1));
+                        }
                     }
-
-                    sv_setpvn(sv, buf, strlen(buf));
                 }
                 break;
 #endif