1ac3dc6693364ffed0bebb6af2982df501392c5d
braney
  Fri Jun 24 16:04:11 2011 -0700
fixes in response to code review with Angie #4352.   Thanks Angie!
diff --git src/hg/hgTracks/snakeTrack.c src/hg/hgTracks/snakeTrack.c
index 5b3f6a4..81a7359 100644
--- src/hg/hgTracks/snakeTrack.c
+++ src/hg/hgTracks/snakeTrack.c
@@ -173,46 +173,36 @@
 // transfer proposedList to new block list
 for(temp=proposedList; temp; temp = next)
     {
     next = temp->next;
     temp->next = NULL;
     slAddHead(&newList, temp);
     }
 }
 
 struct cartOptions
     {
     enum chainColorEnum chainColor; /*  ChromColors, ScoreColors, NoColors */
     int scoreFilter ; /* filter chains by score if > 0 */
     };
 
-static int linkedFeaturesCmpChrom(const void *va, const void *vb)
-/* Help sort linkedFeatures by starting pos. */
-{
-const struct linkedFeatures *a = *((struct linkedFeatures **)va);
-const struct linkedFeatures *b = *((struct linkedFeatures **)vb);
-return strcmp(a->name, b->name);
-}
-
 int snakeHeight(struct track *tg, enum trackVisibility vis)
 /* calculate height of all the snakes being displayed */
 {
 int height = 0;
 struct slList *item = tg->items;
 
-slSort(&tg->items, linkedFeaturesCmpChrom);
-
 item = tg->items;
 
 for (item=tg->items;item; item = item->next)
     {
     height += tg->itemHeight(tg, item);
     }
 return height;
 }
 
 static void doQuery(struct sqlConnection *conn, char *fullName, 
 			struct lm *lm, struct hash *hash, 
 			int start, int end,  boolean isSplit, int chainId)
 /* doQuery- check the database for chain elements between
  * 	start and end.  Use the passed hash to resolve chain
  * 	id's and place the elements into the right
@@ -410,58 +400,58 @@
     tStart = s;
     }
 return size;
 }
 
 int snakeItemHeight(struct track *tg, void *item)
 {
     if (tg->visibility == tvFull)
 	return fullSnakeItemHeight(tg, item);
     else if (tg->visibility == tvPack)
 	return packSnakeItemHeight(tg, item);
 return 0;
 }
 
 static int linkedFeaturesCmpScore(const void *va, const void *vb)
-/* Help sort linkedFeatures by starting pos. */
+/* Help sort linkedFeatures by score */
 {
 const struct linkedFeatures *a = *((struct linkedFeatures **)va);
 const struct linkedFeatures *b = *((struct linkedFeatures **)vb);
 if (a->score > b->score)
     return -1;
 else if (a->score < b->score)
     return 1;
 return 0;
 }
 
 void snakeDraw(struct track *tg, int seqStart, int seqEnd,
         struct hvGfx *hvg, int xOff, int yOff, int width, 
         MgFont *font, Color color, enum trackVisibility vis)
 /* Draw linked features items. */
 {
 struct slList *item;
 int y;
 struct linkedFeatures  *lf;
 double scale = scaleForWindow(width, seqStart, seqEnd);
 int height = snakeHeight(tg, vis);
 
 hvGfxSetClip(hvg, xOff, yOff, width, height);
 
 // score snakes by how many bases they cover
 for (item = tg->items; item != NULL; item = item->next)
     {
-    lf = tg->items;
+    lf = (struct linkedFeatures *)item;
     struct snakeFeature  *sf;
 
     lf->score = 0;
     for (sf =  (struct snakeFeature *)lf->components; sf != NULL;  sf = sf->next)
 	{
 	lf->score += sf->end - sf->start;
 	}
     }
 
 slSort(&tg->items, linkedFeaturesCmpScore);
 
 y = yOff;
 for (item = tg->items; item != NULL; item = item->next)
     {
     if(tg->itemColor != NULL) 
@@ -931,31 +921,31 @@
     struct chain *pChain = lf->extra;
     safef(buf, sizeof(buf), "%d", pChain->id);
     hashAdd(hash, buf, lf);
     overRight = lf->end - seqEnd;
     if (overRight > maxOverRight)
 	maxOverRight = overRight;
     overLeft = seqStart - lf->start ;
     if (overLeft > maxOverLeft)
 	maxOverLeft = overLeft;
     }
 
 if (hash->size)
     {
     boolean isSplit = TRUE;
     /* Make up range query. */
-    sprintf(fullName, "%s_%s", chromName, tg->table);
+    safef(fullName, sizeof fullName, "%s_%s", chromName, tg->table);
     if (!hTableExists(database, fullName))
 	{
 	strcpy(fullName, tg->table);
 	isSplit = FALSE;
 	}
 
     /* in dense mode we don't draw the lines 
      * so we don't need items off the screen 
      */
     if (vis == tvDense)
 	doQuery(conn, fullName, lm,  hash, seqStart, seqEnd,  isSplit, -1);
     else
 	{
 	/* if chains extend beyond edge of window we need to get 
 	 * elements that are off the screen